简介:
php-fpm安装完成后默认不会注册为系统服务,所以需要手工添加系统服务脚本。在/etc/init.d目录下新建php-fpm文件,并更改权限其即可。
1、检测/usr/local/php/var/run/php-fpm.pid是否存
CentOS6.4 添加php-fpm系统服务
在
1.1、不存在:去除/usr/local/php/etc/php-fpm.conf里的“;pid = run/php-fpm.pid”前面的分号,并重启php-fpm就会自动生成php-fpm.pid
1.2、如何重启php-fpm(当然重启系统也是可以的)
1.2.1、查看php-fpm当前的进程ps -ef | grep php-fpm
1.2.2、结束php-fpm所有进程即可 例:kill -9 1228
1.2.3、启动php-fpm:/usr/local/php/sbin/php-fpm
2、新建php-fpm文件
2.1、新建文件:vi /etc/init.d/php-fpm
2.2、添加内容如下
1 #! /bin/sh 2 # Comments to support chkconfig on CentOS 3 # chkconfig: 2345 65 37 4 # 5 set -e 6 7 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 8 DESC="php-fpm daemon" 9 NAME=php-fpm 10 DAEMON=/usr/local/php/sbin/$NAME 11 12 CONFIGFILE=/usr/local/php/etc/php-fpm.conf 13 PIDFILE=/usr/local/php/var/run/$NAME.pid 14 SCRIPTNAME=/etc/init.d/$NAME 15 16 # Gracefully exit if the package has been removed. 17 test -x $DAEMON || exit 0 18 19 d_start() { 20 $DAEMON -y $CONFIGFILE || echo -n " already running" 21 } 22 23 d_stop() { 24 kill -QUIT `cat $PIDFILE` || echo -n " not running" 25 } 26 27 d_reload() { 28 kill -HUP `cat $PIDFILE` || echo -n " can't reload" 29 } 30 31 case "$1" in 32 start) 33 echo -n "Starting $DESC is success" 34 d_start 35 echo "." 36 ;; 37 stop) 38 echo -n "Stopping $DESC is success" 39 d_stop 40 echo "." 41 ;; 42 reload) 43 echo -n "Reloading $DESC configuration..." 44 d_reload 45 echo "reloaded." 46 ;; 47 restart) 48 echo -n "Restarting $DESC is success" 49 d_stop 50 sleep 1 51 d_start 52 echo "." 53 ;; 54 *) 55 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 56 exit 3 57 ;; 58 esac
3、修改其权限并开机启动
3.1、修改权限:chmod 755 /etc/init.d/php-fpm
3.2、开机启动:chkconfig php-fpm on
3.3、查看开机启动的服务:chkconfig --list
4、备注
4.1、启动服务:service php-fpm start
4.2、停止服务:service php-fpm stop
4.3、重启服务:service php-fpm reload
5、结束语
5.1、本文有任何错误,或有任何疑问,欢迎留言说明。
来源:https://www.cnblogs.com/wangmeiqing/p/7591400.html