PHP5.6中php-fpm的配置启动关闭和重启
Posted 歉信君 —— 信真科技·信守真品 www.xinzhenkj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP5.6中php-fpm的配置启动关闭和重启相关的知识,希望对你有一定的参考价值。
转:http://blog.csdn.net/field_yang/article/details/52401994
该文主要讲述:如何配置PHP-fpm、常见报错解决方法和php-fpm的启动、关闭和重启。
LNMP环境中的nginx是不支持php的,需要通过fastcgi插件来处理有关php的请求。而php需要php-fpm这个组件提供该功能。在php5.3.3以前的版本php-fpm是以一个补丁包的形式存在的,而php5.3.3以后只需在编译安装时使用–enable-fpm加载该模块即可,无需另行安装。
[[email protected] php-5.6.25]#/usr/local/php/sbin/php-fpm
[29-Aug-2016 17:36:05] ERROR: failed toopen configuration file ‘/usr/local/php/etc/php-fpm.conf‘: No such file ordirectory (2)
[29-Aug-2016 17:36:05] ERROR: failed toload configuration file ‘/usr/local/php/etc/php-fpm.conf‘
[29-Aug-2016 17:36:05] ERROR: FPMinitialization failed
启动php-fpm发现缺乏配置文件/usr/local/php/etc/php-fpm.conf
此时只需复制php-fpm的配置文件在安装php时提供的配置文件的模版/usr/local/php/etc/php-fpm.conf.default到相应目录下即可,此处有两种方法,均可提供配置文件,即分别将末班复制到/usr/local/php/etc/或者 /usr/local/etc/并重命名为php-fpm.conf
①
[[email protected] etc]# cd /usr/local/php/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf.default
[[email protected] etc]# cp/usr/local/php/etc/php-fpm.conf/usr/local/etc/php-fpm.conf
利用/usr/local/php/sbin/php-fpm启动FPM
[[email protected] etc]# /usr/local/php/sbin/php-fpm
②
[[email protected] etc]#cp php-fpm.conf.defaultphp-fpm.conf
[[email protected] etc]# /usr/local/php/sbin/php-fpm
至此php-fpm配置完成,鉴于fpm是置于PHP和Nginx之间的一层应用,所以配置成服务开机自启。
下面配置php-fpm以服务形式启动
[[email protected] etc]# cd /usr/local/php-5.6.25/
[[email protected] php-5.6.25]# cp./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-5.6.25]# ll /etc/init.d/php-fpm
-rw-r--r-- 1 root root 2354 8月 3115:54 /etc/init.d/php-fpm
[[email protected] php-5.6.25]# chmod a+x/etc/init.d/php-fpm
[[email protected] php-5.6.25]# ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 2354 8月 3115:54 /etc/init.d/php-fpm
[[email protected] php-5.6.25]# /etc/init.d/php-fpmstart
Starting php-fpm [31-Aug-2016 15:56:00]ERROR: unable to bind listening socket for address ‘127.0.0.1:9000‘: Addressalready in use (98)
[31-Aug-2016 15:56:00] ERROR: FPMinitialization failed
Failed
[[email protected] php-5.6.25]# netstat -tunlp |grep9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4928/php-fpm
[[email protected] etc]# /etc/init.d/php-fpm stop
Gracefully shutting down php-fpm warning,no pid file found - php-fpm is not running ?
关闭php-fpm服务时发现报错,缺乏pid文件,解决方法为编辑配置文件,启用pid文件
[[email protected] etc]# vim php-fpm.conf
pid = run/php-fpm.pid
[[email protected] etc]# kill -INT `cat/usr/local/php/var/run/php-fpm.pid`
cat: /usr/local/php/var/run/php-fpm.pid: 没有那个文件或目录
[[email protected] etc]# /etc/init.d/php-fpm stop
Gracefully shutting down php-fpm warning,no pid file found - php-fpm is not running ?
尝试关闭服务时再次报错,手动建立php-fpm.pid文件即可
[[email protected] etc]# cd /usr/local/php/var/run/
[[email protected] run]# vim php-fpm.pid
[[email protected] run]# ls
php-fpm.pid
[[email protected] run]# service php-fpm stop
Gracefully shutting down php-fpm . done
[[email protected] run]# service php-fpm start
Starting php-fpm done
[[email protected] run]# netstat -tunlp |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3008/php-fpm
[[email protected] run]# kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
[[email protected] run]# netstat -tunlp |grep 9000
[[email protected] run]# /etc/init.d/php-fpm start
Startingphp-fpm done
将服务添加到chkconfig列表,设置开机启动
[[email protected] run]# chkconfig --add php-fpm
[[email protected] run]# chkconfig php-fpm on
至此,php-fpm配置完成,下面提供两种控制方式
① PHP-FPM使用信号控制:
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
启动
[[email protected] run]# /usr/local/php/sbin/php-fpm
关闭:
[[email protected] run]# kill -INT `cat/usr/local/php/var/run/php-fpm.pid`
重启:
[[email protected] run]# kill -USR2 `cat/usr/local/php/var/run/php-fpm.pid`
②
服务方式控制
Usage: /etc/init.d/php-fpm{start|stop|force-quit|restart|reload|status}
[[email protected] run]# service php-fpm start
Starting php-fpm done
[[email protected] run]# service php-fpm stop
Gracefully shutting down php-fpm . done
[[email protected] run]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[[email protected] run]#
以上是关于PHP5.6中php-fpm的配置启动关闭和重启的主要内容,如果未能解决你的问题,请参考以下文章