Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to init scripts, but the one I'm using I've copied almost verbatim (I did have to change a few things around from the source I found to work with Fedora). The daemon initializes fastcgi just fine, which was a great victory. However, the init script itself never finishes running, and never returns [ok], even though the program is initialized. It just hangs at "Starting PHP FastCGI" with a blinking cursor. I can't ^C out of it, either.

The init script is below. This is a Fedora14 server.

#chkconfig 3 85 15
#processname: php-fcgi
 . /etc/rc.d/init.d/functions

prog=$(basename $php_cgi)


php_cgi_args="- USER=$user PATH=/usr/bin PHP_FCGI_CHILDREN=$php_fcgi_children PHP_FCGI_MAX_REQUESTS=$php_fcgi_max_requests $php_cgi -b $bind"
start() {
    echo -n "Starting PHP FastCGI: "
    daemon /usr/bin/env $php_cgi_args
    echo "$prog."

stop() {
    echo -n "Stopping PHP FastCGI: "
    killall -q -w -u $user $php_cgi
    echo "$prog."

case "$1" in
    echo "Usage: php-fcgi {start|stop|restart}"
    exit 1
exit $RETVAL
share|improve this question
up vote 0 down vote accepted

Sounds like the php-fcgi process doesn't daemonize by default, which means it will stay in the foreground and block progress just like you have observed. Most applications intended to run as daemons have an option that will cause it to daemonize (in short; run as a background process). If the php-fcgi process does not have such an option you will have to explicitly run it in the background instead, replace the deamon line with something like this:

/usr/bin/env $php_cgi_args >/dev/null 2>&1 &

If the process does any kind of direct logging to standard out or error that you want to be able to look at replace /dev/null above with the name of a log file.

share|improve this answer
Gotcha. I checked the help for php-cgi and it does not have a daemonizing option. I was not aware what 2>&1 & did before; thank you! – Tom Thorogood Oct 6 '11 at 11:08
Funny story: I forgot to ever change this, and my server had to be reprovisioned because it couldn't start up. D'oh! I made sure to make that the first thing to do after the repro. Thanks again for that! – Tom Thorogood Oct 14 '11 at 19:03

Your Answer


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.