1

I have nginx on my server (Ubuntu 11.10). i have created the script below in /etc/init.d/php5cgi to start/stop/restart php5-cgi. the problem is that php5-cgi dies from time to another which makes my website (nginx) giving 502 Bad Gateway (and i dont know why!! it would be highly appreciated if somebody tells us why php5-cgi dies like this).

now, how can i tell my server to keep this process alive forever, in other words to restart it automatically in case it has been stopped (i though in making a shell script and cron job to keep checking, but this means that the website might go down for a minute [from cron to another] and this is not an option for us :( ).

any idea about the reason behind stopping php5cgi very frequently or how to keep it alive forever is highly appreciated.

My /etc/init.d/php5cgi is

COMMAND=/usr/bin/spawn-fcgi
NAME=php5-cgi
ADDRESS=127.0.0.1
PORT=9000
USER=www-data
GROUP=www-data
PHPCGI=/usr/bin/php5-cgi
KILL=/bin/kill

case "$1" in
    start)
        start-stop-daemon --start \
                --exec $COMMAND -- -a $ADDRESS -p $PORT \
                -u $USER -g $GROUP -f $PHPCGI -P /var/run/$NAME.pid|| true
        echo -n "$NAME started with pid "
        cat /var/run/$NAME.pid
        echo
  ;;
    stop)
        if [ -e /var/run/$NAME.pid ]
        then
                $KILL `cat /var/run/$NAME.pid`
                rm /var/run/$NAME.pid
                echo "$NAME stopped"
        else
                echo "$NAME is not running, no pid file in /var/run/"
        fi
  ;;
    restart)
        $0 stop
        $0 start
  ;;
    *)
      echo "Usage: $0 {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL
3
  • Are there any log messages from PHP in /var/log/syslog, or some other file in /var/log?
    – mgorven
    Commented May 1, 2012 at 21:49
  • If you don't have a specific reason for using php5-cgi, perhaps consider using php5-fpm - it is usually regarded as a superior process manager, and in addition to its other advantages, you might get better stability from it. (It is in the Oneiric repository, so it should be a fairly easy switch actually).
    – cyberx86
    Commented May 2, 2012 at 0:28
  • nothing in the error log :( and my php version is 5.2.10.dfsg.1-2ubuntu6 . there is no fpm package for it, i have tried php5-fpm_5.2.10.dfsg.1-2ubuntu6.4+ppa1_amd64.deb but it didn't work (dpkg: error processing php5-fpm (--install): dependency problems - leaving unconfigured) Commented May 2, 2012 at 7:24

0

You must log in to answer this question.

Browse other questions tagged .