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 getting this error:

Starting service:spawn-fcgi: bind failed: Address already in use

When running this command:

/etc/init.d/phpfcgi start

Can someone give me any idea on how to fix it?

Here's my cgi script:

#!/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

SPAWNFCGI="/usr/bin/spawn-fcgi" 
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"
USER=nginx
GROUP=nginx
#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 &"
    daemon $SPAWNFCGI -a ${FCGIADDR} -p ${FCGIPORT} -u ${USER} -g ${GROUP} -P ${PIDFILE} -C ${PHP_FCGI_CHILDREN} -f ${PHPFCGI}
    retval=$?

        #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
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

"Address already in use" means that you have another process that already holds the socket.

You can identify its PID with netstat, using (as root):

netstat -tpan |grep "LISTEN"|grep :9000

The last column gives you PID / process name. Just do a kill -9 PID

share|improve this answer
add comment

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.