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加载该模块即可,无需另行安装。

[root@localhost 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

[root@localhost etc]# cd /usr/local/php/etc/

[root@localhost etc]# ls

pear.conf php-fpm.conf.default

[root@localhost etc]# cp/usr/local/php/etc/php-fpm.conf/usr/local/etc/php-fpm.conf

利用/usr/local/php/sbin/php-fpm启动FPM

[root@localhost etc]# /usr/local/php/sbin/php-fpm

[root@localhost etc]#cp php-fpm.conf.defaultphp-fpm.conf

[root@localhost etc]# /usr/local/php/sbin/php-fpm

 

至此php-fpm配置完成,鉴于fpm是置于PHP和Nginx之间的一层应用,所以配置成服务开机自启。

下面配置php-fpm以服务形式启动

[root@localhost etc]# cd /usr/local/php-5.6.25/

[root@localhost php-5.6.25]# cp./sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm

[root@localhost 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

[root@localhost php-5.6.25]# chmod a+x/etc/init.d/php-fpm

[root@localhost 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

[root@localhost 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

[root@localhost php-5.6.25]# netstat -tunlp |grep9000

tcp       0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      4928/php-fpm

 [root@localhost 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文件

[root@localhost etc]# vim php-fpm.conf

pid = run/php-fpm.pid

[root@localhost etc]# kill -INT `cat/usr/local/php/var/run/php-fpm.pid`

cat: /usr/local/php/var/run/php-fpm.pid: 没有那个文件或目录

[root@localhost 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文件即可

[root@localhost etc]# cd /usr/local/php/var/run/

[root@localhost run]# vim php-fpm.pid

[root@localhost run]# ls

php-fpm.pid

[root@localhost run]# service php-fpm stop

Gracefully shutting down php-fpm . done

[root@localhost run]# service php-fpm start

Starting php-fpm done

[root@localhost run]# netstat -tunlp |grep 9000

tcp       0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3008/php-fpm

[root@localhost run]# kill -INT `cat /usr/local/php/var/run/php-fpm.pid`

[root@localhost run]# netstat -tunlp |grep 9000

[root@localhost run]#  /etc/init.d/php-fpm start

Startingphp-fpm  done

将服务添加到chkconfig列表,设置开机启动

[root@localhost run]# chkconfig --add php-fpm

[root@localhost run]# chkconfig php-fpm on

 

至此,php-fpm配置完成,下面提供两种控制方式

① PHP-FPM使用信号控制:

INT, TERM 立刻终止

QUIT 平滑终止

USR1 重新打开日志文件

USR2 平滑重载所有worker进程并重新载入配置和二进制模块

启动

[root@localhost run]# /usr/local/php/sbin/php-fpm

关闭:

[root@localhost run]# kill -INT `cat/usr/local/php/var/run/php-fpm.pid`

重启:

[root@localhost 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}

[root@localhost run]# service php-fpm start

Starting php-fpm done

[root@localhost run]# service php-fpm stop

Gracefully shutting down php-fpm . done

[root@localhost run]#  /etc/init.d/php-fpm restart

Gracefully shutting down php-fpm . done

Starting php-fpm done

[root@localhost run]#

上一篇:Unity性能优化降低DrawCall


下一篇:通过http方式关闭和重启Jenkins