Project

General

Profile

Mod_Fastgi Load Balanced With PHP

Added by JustinK101 almost 8 years ago

Hello, we are running lighttpd/1.4.28 (ssl) and have setup mod_fastcgi to push .php requests to a separate and dedicated PHP processing server(192.168.167.82). On the web server with lighttpd (192.168.167.81), we don't have PHP installed, as I don't think its required. Also, correct me if I am wrong, on the PHP processing server we don't have lighttpd installed.

Our lighttpd configuration looks like:

#### fastcgi module
fastcgi.server             = ( ".php" =>
                               ( "PHP" =>
                                 (
                                   "host" => "192.168.167.82",
                                   "port" => 8080,
                                   "bin-path" => "/usr/bin/php-cgi" 
                                 )
                               )
                             )

Port 8080 is open on both the web server, and PHP processing server. The problem, when we start lighttpd, the following is logged:

2011-04-12 16:29:52: (log.c.166) server started
2011-04-12 16:29:52: (mod_fastcgi.c.978) bind failed for: tcp:192.168.167.82:8080 Cannot assign requested address
2011-04-12 16:29:52: (mod_fastcgi.c.1399) [ERROR]: spawning fcgi failed.
2011-04-12 16:29:52: (server.c.938) Configuration of plugins failed. Going down.

Ideas?

Replies (9)

RE: Mod_Fastgi Load Balanced With PHP - Added by nitrox almost 8 years ago

If you remove the bin-path?

RE: Mod_Fastgi Load Balanced With PHP - Added by JustinK101 almost 8 years ago

nitrox,

So, we disabled bin-path and now lighttpd starts, but when we try and visit a PHP page, the following is logged in the lighttpd error log:

2011-04-13 14:43:32: (mod_fastcgi.c.2906) establishing connection failed: Connection refused socket: tcp:192.168.167.82:8080
2011-04-13 14:43:32: (mod_fastcgi.c.2912) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1
2011-04-13 14:43:34: (mod_fastcgi.c.2854) fcgi-server re-enabled: tcp:192.168.167.82:8080

Also, the response is 503 - Server Not Available. Do we have to start php-cgi or anything special on the app server (192.168.167.82)?

RE: Mod_Fastgi Load Balanced With PHP - Added by Olaf-van-der-Spek almost 8 years ago

JustinK101 wrote:

Also, the response is 503 - Server Not Available. Do we have to start php-cgi or anything special on the app server (192.168.167.82)?

Who else is going to start it? ;)

RE: Mod_Fastgi Load Balanced With PHP - Added by JustinK101 almost 8 years ago

Sorry, I am nobo, can you give an example, of how we start it on the PHP server? It is simply:

$ php-cgi &

Looking at man php, I see the following as well:

$ php -b address:port
Bind Path for external FASTCGI Server mode (CGI only).

Should I use php -b or just php-cgi? Thanks.

RE: Mod_Fastgi Load Balanced With PHP - Added by JustinK101 almost 8 years ago

So, getting close. Now I am getting: "No input file specified."

The web server (192.168.167.81) has lighttpd installed with the following config:

fastcgi.server             = ( ".php" =>
                               ( "192.168.167.82" =>
                                 (
                                   "host" => "192.168.167.82",
                                   "port" => 8080,
                                   "check-local" => "disable",
                                   "disable-time" => 3
                                 )
                               )
                             )

The application/php server (192.168.167.82) has PHP 5.3 and spawn-fcgi installed, with the following script in /etc/init.d/phpfcgi

#!/bin/sh
#
# fcgi     Startup script for fcgi
#
# processname: fcgi

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

FCGI_DAEMON="/usr/local/bin/spawn-fcgi" 
FCGI_PORT=8080
FCGI_PROGRAM="/usr/bin/php-cgi" 
#FCGI_SOCKET="/tmp/php-fastcgi.sock" 
FCGI_PIDFILE="/var/run/spawn-fcgi.pid" 
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
prog="fcgi" 

export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS

RETVAL=0

start() {
        echo -n $"Starting $prog: " 
        daemon $FCGI_DAEMON -f $FCGI_PROGRAM -p $FCGI_PORT -C $PHP_FCGI_CHILDREN -P $FCGI_PIDFILE
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: " 
        rm -f $FCGI_PIDFILE
        killproc $FCGI_PROGRAM
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        condrestart)
                if [ -f /var/lock/subsys/$prog ]; then                                                                        
                        stop
                        start
                fi
                ;;
        status)
                   status $lighttpd
                RETVAL=$?
                ;;
        *)
              echo $"Usage: $0 {start|stop|restart|condrestart|status}" 
                RETVAL=1
esac

exit $RETVAL

RE: Mod_Fastgi Load Balanced With PHP - Added by JustinK101 almost 8 years ago

Think we figured out the problem, the web files have to both be on the web server and application server. Is there anyway around that? That is a nightmare to manage.

RE: Mod_Fastgi Load Balanced With PHP - Added by nitrox almost 8 years ago

Or git or rsync, simple push to all machines should do the trick.

    (1-9/9)