CentOS下搭建nginx+php环境

一.下载安装nginx

参见 http://www.cnblogs.com/kreo/p/4378086.html

不再赘述

二.下载php

#下载
wget http://bg2.php.net/distributions/php-5.6.7.tar.gz
#解压
tar zxvf php-5.6.7.tar.gz
#编译
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=/u01/mysql5.6.23 --enable-mbstring --with-mysqli=/u01/mysql5.6.23/bin/mysql_config

三.启动fastcgi代理模块 php-fpm

初始没有默认配置文件,用default创建一个

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

启动fpm模块

/usr/local/php/sbin/php-fpm

新版本的php-fpm已经不再支持[start|stop|restart]参数命令了,想要关闭重启,需要用kill pid管道方式

#php-fpm 启动:
/usr/local/php/sbin/php-fpm
#php-fpm 关闭:
kill -INT `cat /var/run/php-fpm/php-fpm.pid`
#php-fpm 重启:
kill -USR2 `cat /var/run/php-fpm/php-fpm.pid`

注意 /var/run/php-fpm/php-fpm.pid文件路径是php-fpm.conf定义的,如果没有定义,则用 ps -ef|grep php-fpm得到master进程的pid,然后kill -INT pid

四.配置nginx

server {
        listen       80;
        server_name  localhost;
        charset utf-8;
        root /u01/php/;
        index  index.html index.htm index.php;
        location / {
        }
        location ~ .php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
}
原文地址:https://www.cnblogs.com/kreo/p/4392173.html