首先,在编译时带上 --enable-fpm
参数:
[root@localhost local]# yum -y install libxml2 libxml2-devel gd gd-devel
[root@localhost local]# wget http://cn2.php.net/distributions/php-7.2.0.tar.gz
[root@localhost local]# tar -zxvf php-7.2.0.tar.gz
[root@localhost local]# cd php-7.2.0
[root@localhost php-7.2.0]# ./configure
--prefix=/usr/local/php
--with-config-file-path=/usr/local/php/etc
--with-gd
--enable-pdo
--with-mysqli=mysqlnd
--with-pdo-mysql=mysqlnd
--enable-mysqlnd-compression-support
--enable-mbstring
--enable-zip
--enable-swoole
--enable-fpm
[root@localhost php-7.2.0]# make && make install
如果是已经安装过,可以通过以下方式查看之前的编译参数:
/usr/bin/php -i | grep Configure
# 或者
cd /lamp/php-7.2.0 & cat config.nice
创建相关配置文件:
[root@localhost php-7.2.0]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-7.2.0]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.0]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
配置系统服务和环境变量:
[root@localhost php-7.2.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.0]# chmod +x /etc/init.d/php-fpm
[root@localhost php-7.2.0]# ln -s /etc/init.d/php-fpm /usr/bin/
[root@localhost ~]# vim /etc/profile
export PATH=/usr/local/php/bin:$PATH #最后面添加
[root@localhost ~]# source /etc/profile
[root@localhost ~]# php -v
编辑配置文件:
# vim php-fpm.conf
pid = /usr/local/php/var/run/php-fpm.pid
user = www
group = www
创建用户和用户组:
groupadd www
useradd -g www www
使用命令启动:
/usr/local/php/sbin/php-fpm
查看进行:
ps -ef | grep php-fpm
查看端口:
netstat -tnl | grep 9000
配置开机启动:
# vi /etc/rc.local 加入
/usr/local/php/sbin/php-fpm
关闭FPM:
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
重启FPM:
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
信号说明:
INT/TERM 强制终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有master和worker