開啟PHP服務的方法

2020-07-16 10:05:49

安裝完php,使用chkconfig命令來檢視php-fpm服務是否開啟,如果沒有開啟

1、在/etc/init.d/目錄下建立指令碼php-fpm

vim/etc/init.d/php-fpm

2、編寫指令碼內容(將一下複製進去相應改動安裝路徑)

#!/bin/sh
     #
     # php-fpm - this script starts and stops the php-fpm daemin
     #
     # chkconfig: - 85 15
     # processname: php-fpm
     # config:      /usr/local/php/etc/php-fpm.conf
     set -e
     PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
     DESC="php-fpm daemon"
     NAME=php-fpm
     DAEMON=/usr/local/php/sbin/$NAME                 //這裡改成之前的安裝目錄
     CONFIGFILE=/usr/local/php/etc/php-fpm.conf      //這裡改成之前的安裝目錄
     PIDFILE=/usr/local/php/var/run/$NAME.pid         //這裡改成之前的安裝目錄
     SCRIPTNAME=/etc/init.d/$NAME                         //這裡改成之前的安裝目錄    
     # If the daemon file is not found, terminate the script.
     test -x $DAEMON || exit 0
     d_start(){
         $DAEMON -y $CONFIGFILE || echo -n " already running"
     }
     d_stop(){
         kill -QUIT `cat $PIDFILE` || echo -n " no running"
     }
     d_reload(){
         kill -HUP `cat $PIDFILE` || echo -n " could notreload"
     }
     case "$1" in
         start)
             echo -n "Starting $DESC: $NAME"
             d_start
             echo "."
             ;;
         stop)
             echo -n "Stopping $DESC: $NAME"
             d_stop
             echo "."
             ;;
         reload)
             echo -n "Reloading $DESCconfiguration..."
             d_reload
             echo "Reloaded."
             ;;
         restart)
             echo -n "Restarting $DESC: $NAME"
             d_stop
             # Sleep for two seconds before startingagain, this should give the nginx daemon some time to perform a graceful stop
             sleep 2
             d_start
             echo "."
             ;;
         *)
             echo "Usage: $SCRIPTNAME{start|stop|restart|force-reload)" >&2
             exit 3
             ;;
     esac
     exit 0

最後:wq退出儲存;

3、更改指令碼許可權

chmod775 /etc.init.d/php-fpm

4、設定開機啟動

chkconfigphp-fpm on

可以用命令chkconfig檢視開機服務列表

相關推薦:

PHP視訊教學:https://www.php.cn/course/list/29/type/2.html

以上就是開啟PHP服務的方法的詳細內容,更多請關注TW511.COM其它相關文章!