nginx安装php环境

1.php下载地址

https://secure.php.net/downloads.php(此次安装版本为7.0.33)

2.安装依赖的包

yum -y install libxml2
yum -y install libxml2-devel
yum -y install openssl
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install libjpeg
yum -y install libjpeg-devel
yum -y install libpng
yum -y install libpng-devel
yum -y install freetype
yum -y install freetype-devel
yum -y install pcre
yum -y install pcre-devel
yum -y install libxslt
yum -y install libxslt-devel
yum -y install bzip2
yum -y install bzip2-devel

3.解压&&安装

./configure  --enable-fpm

make && make install

4.nginx整合php-fpm

 启动php-fpm报错: /usr/local/sbin/php-fpm

ERROR: failed to open configuration file '/usr/local/etc/php-fpm.conf': No such file or directory (2)
ERROR: failed to load configuration file '/usr/local/etc/php-fpm.conf'
ERROR: FPM initialization failed

到/usr/local/etc/目录下,将php-fpm.conf.default拷贝一份成php-fpm.conf

然后在编辑php-fpm.conf配置文件

最后一行改成如下

include=/usr/local/etc/php-fpm.d/*.conf

进入到/usr/local/etc/php-fpm.d/目录下,将www.conf.default拷贝一份成www.conf

编辑www.conf文件,将user和group改成和nginx.conf中的user和group一致

user = www
group = www

再次启动:/usr/local/sbin/php-fpm

5.修改nginx配置文件,添加php配置

location ~ \.php$ {
                        root html; #指定php的根目录
                        fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include fastcgi_params;
                }

修改nginx启动用户

测试nginx.conf是否修改成功:

/usr/local/nginx/sbin/nginx  -t

重新载入配置文件:

/usr/local/nginx/sbin/nginx -s reload

6.测试访问php程序

在nginx的root目录下创建test.php文件(root路径:/usr/local/nginx/html)

<?php
    phpinfo();
?>

访问nginx地址:192.168.x.x/test.php

如出现下面回显图片,则表明php环境安装成功。

补充:

如果需要服务器默认支持index.php为首页,修改nginx中location配置

 

posted @ 2018-12-27 16:23  噔噔蹬蹬  阅读(223)  评论(0编辑  收藏  举报