Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using php-cgi on ubuntu(with nginx), and the command to start it is:

spawn-fcgi -a 127.0.0.1 -p 9100 -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

but sometimes the php-cgi process will exit automatically, and I need to start it manually. Is there any way that can make it restart automatically, eg) write init script?

Please suggest, thanks.

share|improve this question

2 Answers 2

You should really use PHP-FPM instead of spawn-fcgi. It's a fastcgi process manager which was written to overcome many of the problems with php-cgi (and thus with spawn-fcgi by relation).

Since the 5.2.x line of PHP is end of life'd you should also be on PHP 5.3.x which means you most likely already have php-fpm and it's just a matter of making sure your package manager installs that version (see if it's called php-fpm or similar). If you install from source then it's just a compile time flag to enable it. (--with-fpm)

If you're on 5.2.x and you're too enterprise for your boss to allow you to upgrade then you'll have to monitor it with something like Supervisord or Monit

share|improve this answer

I currently use upstart (initctl).

http://manpages.ubuntu.com/manpages/lucid/man8/initctl.8.html

I'm running CentOS 6, but I think the process is similar for Ubuntu. For CentOS, create the file /etc/init/php-cgi.conf containing:

# Upstart event
# nginx_start - start nginx web server / proxy
#

start on runlevel 3
stop on runlevel [016]
console output

exec /usr/bin/php-cgi -b 127.0.0.1:9001

respawn

respawn limit 10 90

Then you can control it with initctl:

initctl start php-cgi
initctl status php-cgi
initctl stop php-cgi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.