Nginx+PHP(FastCGI)环境搭建

 在网上搜了几篇相关文章,内容都大同小异。还是自己动手搭建吧,顺带记录下过程留给需要的朋友们。


1安装Nginx

安装Nginx,具体步骤就不赘述了。


2安装MySQL

Ø  安装MySQL:yum installmysql-server

Ø  启动MySQL服务:servicemysqld start或cd /usr ; /usr/bin/mysqld_safe &

Ø  检查是否启动:lsof –i:3306


3安装FastCGI

Ø  安装PHP-FPM:yum installphp-fpm.x86_64

Ø  将/etc/php-fpm.d/www.conf中user和group的值从apache改为admin

Ø  启动PHP-FPM:/usr/sbin/php-fpm -D

Ø  检查是否启动:lsof –i:9000


4入门实例

4.1部署PHP项目

在/data/discuzXRoot下,创建测试PHP网页test.php,命令为:

echo “<?phpphpinfo();?>” > test.php

注意:discuzXRoot文件夹用户必须与NginxPHP-FPM的用户(admin)相同,修改文件夹用户组命令为:chown –Radmin:admin discuzXRoot


4.2新建Nginx配置文件

在nginx/conf/下,新建配置文件discuzx.com(在nginx.conf主配置文件中引入),内容如下:

===============================================================================

server  

   {  

       listen 80;  

       server_name discuzx.com;  

       index index.php;  

       root /data/discuzXRoot;  

       location ~ .*\.(php|php5)?$  

       {  

           fastcgi_pass 127.0.0.1:9000;  

           fastcgi_index index.php;  

           include fastcgi.conf;  

       }  

}  


4.3重启Nginx

重新加载配置文件:nginx –s reload

参考文章

nginx+php的配置

http://www.cnblogs.com/jsckdao/archive/2011/05/05/2038265.html

实战Nginx与PHP(FastCGI)的安装、配置与优化

http://www.myhack58.com/Article/sort099/sort0102/2012/33364.htm

正确设置 php-fpm子进程用户

http://hi.baidu.com/mylnx/item/7310cecee990607689ad9e9e

原文地址:https://www.cnblogs.com/xiaomaohai/p/6157754.html