nginx + php ( php-fpm )编译安装

时间:2022-10-20 15:20:20

这里用的是nginx1.9, php5.3.28

本例是在CentOS6.3上的部署


先准备好nginx和它依赖的源码包:pcre, openssl, zlib


1>安装nginx


tar zxvf pcre-8.36.tar.gz
tar zxvf openssl-1.0.2-latest.tar.gz
tar zxvf zlib-1.2.8.tar.gz
mv pcre-8.36 /usr/local/src/
mv zlib-1.2.8 /usr/local/src/
mv openssl-1.0.2 /usr/local/src/
./configure --with-pcre=/usr/local/src/pcre-8.36 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2a
make
make install


2>安装php:
./configure --prefix=/usr/local/php  --enable-fpm --enable-pdo --enable-inline-optimization --with-zlib --enable-sockets --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mbstring --enable-mbregex
make clean
make
make install

这里用较少的选项,不必来太多的库,多了反而容易出问题。如果已经make过,一定要make clean。

编辑php.ini:

vi /usr/local/php/lib/php.ini

mysql.default_socket=/var/lib/mysql/mysql.sock
mysqli.default_socket=/var/lib/mysql/mysql.sock
pdo_mysql.default_socket=/var/lib/mysql/mysql.sock


3>启动php-fpm和nginx:

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

终止php-fpm进程,先查看它的主进程:

ps aux | grep php-fpm.conf

然后kill掉:

kill -9 $php-fpm-master.pid

kill -9 $php-fpm-worker1.pid $php-fpm-worker2.pid

结束nginx进程类似

可以写个 shell脚本,方便控制。