chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
#然后就可以启动服务了
systemctl restart nginx.service
#或
/etc/init.d/nginx start
Nginx安装完毕 ,下面开始整合Nginx与PHP
六、整合Nginx与PHP
1、编辑Nginx.conf,启用如下选项:
cd /usr/local/nginx/conf/
cat nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
# mv fastcgi_paramsfastcgi_params.bak
# cat fastcgi_params
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
在所支持的主页面格式中添加php格式的主页,类似如下:
location / {
root html;
index index.php index.html index.htm;
}
#重新载入配置
# /etc/init.d/nginx reload
3、在/usr/local/nginx/html目录下新建index.php测试页面
cat > /usr/local/nignx/htmlindex.php << EOF
<?php
phpinfo();
?>
可通过浏览器 访问此测试页面,验证nginx连接php配置是否成功。页面应该如下图
至此CenOS72下LNMP编译安装完毕!
LNMP安装参考如下文章
Ubuntu 16.04 下源码配置LNMP开发环境