linux(centos)下设置php-fpm开机自启动

首先,新建php-fpm文件

    vim /etc/init.d/php-fpm

    然后加入对应的脚本文件:

 

[plain]  view plain  copy
  1. #!/bin/sh    
  2. # chkconfig:   2345 15 95  
  3.   
  4. # description:  PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \  
  5.   
  6. # with some additional features useful for sites of any size, especially busier sites.  
  7. # DateTime: 2016-09-20  
  8.   
  9. # Source function library.    
  10. . /etc/rc.d/init.d/functions    
  11.   
  12. # Source networking configuration.    
  13. . /etc/sysconfig/network    
  14.   
  15. # Check that networking is up.    
  16. [ "$NETWORKING" = "no" ] && exit 0    
  17.   
  18. phpfpm="/usr/local/php/sbin/php-fpm"    
  19. prog=$(basename ${phpfpm})    
  20.   
  21. lockfile=/var/lock/subsys/phpfpm  
  22.   
  23. start() {    
  24.     [ -x ${phpfpm} ] || exit 5    
  25.     echo -n $"Starting $prog: "    
  26.     daemon ${phpfpm}  
  27.     retval=$?    
  28.     echo    
  29.     [ $retval -eq 0 ] && touch $lockfile    
  30.     return $retval    
  31. }    
  32.   
  33. stop() {    
  34.     echo -n $"Stopping $prog: "    
  35.     killproc $prog -QUIT    
  36.     retval=$?    
  37.     echo    
  38.     [ $retval -eq 0 ] && rm -f $lockfile    
  39.     return $retval    
  40. }    
  41.   
  42. restart() {    
  43.     configtest || return $?    
  44.     stop    
  45.     start    
  46. }    
  47.   
  48. reload() {    
  49.     configtest || return $?    
  50.     echo -n $"Reloading $prog: "    
  51.     killproc ${phpfpm} -HUP    
  52.     RETVAL=$?    
  53.     echo    
  54. }    
  55.   
  56. force_reload() {    
  57.     restart    
  58. }    
  59.   
  60. configtest() {    
  61.   ${phpfpm} -t  
  62. }    
  63.   
  64. rh_status() {    
  65.     status $prog    
  66. }    
  67.   
  68. rh_status_q() {    
  69.     rh_status >/dev/null 2>&1    
  70. }    
  71.   
  72. case "$1" in    
  73.     start)    
  74.         rh_status_q && exit 0    
  75.         $1    
  76.         ;;    
  77.     stop)    
  78.         rh_status_q || exit 0    
  79.         $1    
  80.         ;;    
  81.     restart|configtest)    
  82.         $1    
  83.         ;;    
  84.     reload)    
  85.         rh_status_q || exit 7    
  86.         $1    
  87.         ;;    
  88.     status)    
  89.         rh_status    
  90.         ;;    
  91.     *)    
  92.         echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"    
  93.         exit 2    
  94. esac      
     然后设置加入到开机启动项里面:

   chkconfig --add /etc/init.d/php-fpm

   接下来使用命令来检测:

   service php-fpm start

   service php-fpm stop

   如果失败,请检测php-fpm文件执行权限是否足够

   最后,chkconfig php-fpm on 来设置开机启动,ok这样子就完成啦

转载自  https://blog.csdn.net/lzy0613/article/details/76300371

猜你喜欢

转载自blog.csdn.net/a315821168/article/details/80333936