Nginx - PHP/FastCGI Init Script

這支script適用於Redhat, Centos, Fedora
#vi /etc/init.d/phpfcgi


#!/bin/bash
#
# Startup script for the PHP FastCGI server.
#
# chkconfig: 345 85 15
# description: PHP is an HTML-embedded scripting language
# processname: php
# config: /etc/php.ini

# Source function library.
. /etc/rc.d/init.d/functions

PHPFCGI="/usr/bin/php-cgi"
FCGIPORT="9000"
FCGIADDR="127.0.0.1"
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
ALLOWED_ENV="PATH USER"
PHPUSER=php
PIDFILE=/var/run/phpfcgi.pid

if [ -z "$PHP_FCGI_CHILDREN" ]; then
  PHP_FCGI_CHILDREN=5
fi

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"

case "$1" in
  start)
        PHPFCGI_START=$"Starting ${NAME} service: "
        echo -n $PHPFCGI_START

        # check for $PHPUSER, create if non-existent
        if [ -z "`id -u $PHPUSER 2> /dev/null`" ]; then
            useradd -s /sbin/nologin $PHPUSER
        fi

        # clean environment
        E=
        for i in $ALLOWED_ENV; do E="$E $i=${!i}"; done
        daemon --user $PHPUSER --pidfile $PIDFILE "env - $E $PHPFCGI -q -b $FCGIADDR:$FCGIPORT &> /dev/null &"

        pid=`pidof php-cgi`
        if [ -n "$pid" ]; then
            echo $pid > $PIDFILE
            success $PHPFCGI_START
        else
            failure $PHPFCGI_START
        fi
        echo
        ;;
  stop)
        echo -n "Stopping php-fcgi: "
        killproc -p $PIDFILE phpfcgi
        echo
        ;;
  status)
        status phpfcgi
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit 0

#chmod +x /etc/init.d/phpfcgi
#chkconfig --add phpfcgi
#chkconfig phpfcgi on
#service phpfcgi start
#service phpfcgi stop

By tony

自由軟體愛好者~喜歡不斷的思考各種問題,有新的事物都會想去學習嘗試 做實驗並熱衷研究 沒有所謂頂天的技術 只有謙虛及不斷的學習 精進專業,本站主要以分享系統及網路相關知識、資源而建立。 Github http://stnet253.github.io

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料