# 将php-fpm设置成服务,并实现开机自动启动
# 说明:作者仅在CentOS7.0上进行了测试,而且没有进行可靠性和稳定性的测试!
vi /etc/rc.d/init.d/fpm chmod +x /etc/rc.d/init.d/fpm chkconfig --add fpm chkconfig fpm on
/etc/rc.d/init.d/fpm文件的内容如下:
#! /bin/sh #chkconfig: 2345 60 90 ## vi /opt/php/etc/php-fpm.conf #uncomment pid under [global] #pid = run/php-fpm.pid ## vi /etc/rc.d/init.d/fpm ## chmod +x /etc/rc.d/init.d/fpm ## chkconfig --add fpm ## chkconfig fpm on PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="php-fpm daemon" NAME=php-fpm INSTALLDIR=/opt/php DAEMON=$INSTALLDIR/sbin/$NAME CONFIGFILE=$INSTALLDIR/lib/$NAME.conf PIDFILE=$INSTALLDIR/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -D || echo -n "php-fpm already running" } do_stop() { kill -INT `cat $PIDFILE` || echo -n "php-fpm not running" } do_test() { $DAEMON -t || echo -n "php-fpm can‘t test" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; test) echo -n "Testing $DESC: $NAME" do_test echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|test}" >&2 exit 3 ;; esac exit 0
使用命令如下:
service fpm start service fpm stop service fpm restart service fpm test
时间: 2024-10-11 16:26:30