NSLU2-Linux
view · edit · print · history

HowTo.DeployPHPWebAppUsingFastCGI History

Hide minor edits - Show changes to markup

October 28, 2009, at 05:01 PM by frater -- lighttpd.conf has wrong event handler on DD-WRT
Added lines 448-456:

On DD-WRT it needs server.event-handler = "poll" in /opt/etc/lighttpd/lighttpd.conf

The latest package writes a config without it and fails /opt/sbin/lighttpd -f /opt/etc/lighttpd/lighttpd.conf -D

 fdevent_linux_sysepoll.c.131: epoll_create failed (Function not implemented), try to set server.event-handler = "poll" or "select"
October 17, 2008, at 08:05 PM by slugmanbashi -- Restore from spam
Changed lines 1-2 from:

Very nice site! <a href="http://training.cvc4.org/pharm1/14169/1.html">cheap viagra</a>

to:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

October 17, 2008, at 10:49 AM by John804 -- wirryuyu
Changed lines 1-447 from:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

to:

Very nice site! <a href="http://training.cvc4.org/pharm1/14169/1.html">cheap viagra</a>

October 12, 2008, at 12:03 PM by drno -- spam revert
Changed lines 1-2 from:

Very nice site! [url=http://training.cvc4.org/pharm1/14164/2.html]cheap cialis[/url]

to:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

October 12, 2008, at 11:00 AM by John1613 -- toopiupw
Changed line 2 from:

<a href="http://training.cvc4.org/pharm1/14164/1.html">cheap viagra</a>

to:

[url=http://training.cvc4.org/pharm1/14164/2.html]cheap cialis[/url]

October 12, 2008, at 11:00 AM by John1613 -- toopiupw
Changed lines 1-447 from:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

to:

Very nice site! <a href="http://training.cvc4.org/pharm1/14164/1.html">cheap viagra</a>

October 10, 2008, at 09:54 AM by pembo -- removed spam
Changed lines 1-2 from:

Very nice site! <a href="http://training.cvc4.org/pharm1/14162/1.html">cheap viagra</a>

to:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

October 10, 2008, at 09:24 AM by John1391 -- eitopwwe
Changed lines 1-447 from:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

to:

Very nice site! <a href="http://training.cvc4.org/pharm1/14162/1.html">cheap viagra</a>

October 10, 2008, at 09:17 AM by pembo -- Removed spam
Changed lines 1-2 from:

Very nice site! [url=http://training.cvc4.org/pharm1/14161/2.html]cheap cialis[/url]

to:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

October 09, 2008, at 11:58 AM by John1127 -- tieuyteo
Changed line 2 from:

<a href="http://training.cvc4.org/pharm1/14161/1.html">cheap viagra</a>

to:

[url=http://training.cvc4.org/pharm1/14161/2.html]cheap cialis[/url]

October 09, 2008, at 11:58 AM by John1127 -- tieuyteo
Changed lines 1-447 from:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

to:

Very nice site! <a href="http://training.cvc4.org/pharm1/14161/1.html">cheap viagra</a>

October 08, 2008, at 04:32 PM by ByronT -- Remove Spam
Changed lines 1-447 from:

Very nice site!

to:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

October 08, 2008, at 12:02 PM by John1300 -- ietrrteu
Changed lines 1-2 from:

Very nice site! http://training.cvc4.org/pharm1/14160/4.html

to:

Very nice site!

October 08, 2008, at 12:02 PM by John1308 -- wetituri
Changed line 2 from:

[LINK http://training.cvc4.org/pharm1/14160/3.html]cheap tramadol[/LINK]

to:

http://training.cvc4.org/pharm1/14160/4.html

October 08, 2008, at 12:02 PM by John1446 -- pooryyrr
Changed line 2 from:

[url=http://training.cvc4.org/pharm1/14160/2.html]cheap cialis[/url]

to:

[LINK http://training.cvc4.org/pharm1/14160/3.html]cheap tramadol[/LINK]

October 08, 2008, at 12:02 PM by John565 -- rupipter
Changed line 2 from:

<a href="http://training.cvc4.org/pharm1/14160/1.html">cheap viagra</a>

to:

[url=http://training.cvc4.org/pharm1/14160/2.html]cheap cialis[/url]

October 08, 2008, at 12:02 PM by John1544 -- eoeewuiy
October 08, 2008, at 12:02 PM by John631 -- pyeeuyur
Changed lines 1-447 from:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.


Install PHP & php-fcgi packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi
# ipkg install libstdc++ 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/test-php/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)

Launch php-fcgi command (remember to add a trailing & to launch in background). (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)


Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install lighttpd 

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install cherokee

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).

Configure & launching the web server

cherokee

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated. Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Port 8082
IPv6 Off
Timeout 60
KeepAlive On
MaxKeepAliveRequests 500
ServerTokens Full
PidFile /home/mylogin/tmp/cherokee.pid
Icons /opt/etc/cherokee/icons.conf
MimeFile /opt/etc/cherokee/mime.types
MimeFile /opt/etc/cherokee/mime.compression.types
Include /opt/etc/cherokee/advanced.conf
Include /opt/etc/cherokee/mods-enabled
Documentroot /home/mylogin/test-php
DirectoryIndex index.html
Extension php, php3, php4, php5 {
  Handler fcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
    }
  }
}

(:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Or lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.port                = 8081
server.modules              = (
                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )
server.document-root        = "/home/mylogin/test-php"
server.errorlog             = "/home/mylogin/test-php/error.log"
accesslog.filename          = "/home/mylogin/test-php/access.log"
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
fastcgi.server    = ( ".php" =>
                      ( "localhost" =>
                        (
                          "socket" => "/tmp/php-fcgi.sock",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
                               )
                             )
                           )
                        )

(:tableend:)

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf 

(:tableend:)

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 

(:tableend:)

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:) It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
}

(:tableend:)

  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=250

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH SHELL USER"

## user and group to run PHP-FCGI
USERID=www
GROUPID=everyone

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 3
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

RobHam - March 2007


''I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected''

anyone can help me?
i am really new at this and feel totally lost

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.


Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de as a lazy way to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.
JBrown? March 2008

to:

Very nice site! <a href="http://training.cvc4.org/pharm1/14160/1.html">cheap viagra</a>

September 07, 2008, at 04:25 PM by thx1011 -- Note about default server root and php files
Added lines 224-226:

Note:
If using the default installation parameters the Server Root is on /opt/share/www, and not in /opt/share/www/lighthttp. So your first php test files should be located on the prior directory and not the former.

August 08, 2008, at 07:41 AM by Viktor K --
Changed lines 51-52 from:
  • Vikezz, I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).
to:
  • Vikezz: I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).
August 08, 2008, at 07:41 AM by Viktor K --
Changed lines 51-52 from:

Over at http://unslung.blogspot.com there is a guide to install Cherokee 0.7.2 on a slug.

to:
  • Vikezz, I've made a new guide over at http://unslung.blogspot.com. It will guide you through an installation of the Cherokee 0.7.2 webserver on a slug(unslung).
August 08, 2008, at 07:36 AM by Viktor K -- cherokee webserver install
Added lines 51-52:

Over at http://unslung.blogspot.com there is a guide to install Cherokee 0.7.2 on a slug.

July 12, 2008, at 03:39 PM by Platypen --
Changed line 25 from:

Launch php-fcgi command.

to:

Launch php-fcgi command (remember to add a trailing & to launch in background).

April 24, 2008, at 04:45 PM by Jason -- php-fcgi lighttpd config
Added lines 201-202:

The current version of php-fcgi creates the fastcgi.server variables in /opt/etc/lighttpd/conf.d/10-php-fcgi.conf so if that file is included you will get a "Duplicate config variable in conditional" from lighty

March 28, 2008, at 02:56 AM by Jim --
Added lines 59-72:

This is what I had to do to update from 0.5.6-3 to 0.6.1-2:

  Use the new cherokee.conf file
  Use the new mime.types file
  Use the new S80cherokee file

  Edit /opt/etc/cherokee/cherokee.conf file
    Possible changes
      server!port = 8008	'use the correct port here		
      server!port_tls = 8008	'use the correct port here
      vserver!default!directory_index = index.php,index.html	'use the correct file extensions here
        'I use index.htm as the updates have overwritten the index.html file with a cherokee default one.

Jim

March 27, 2008, at 05:52 PM by BrianZhou -- cherokee 0.6.1
Changed lines 57-58 from:
to:

Configuration instruction for 0.6.1-1 at http://tech.groups.yahoo.com/group/nslu2-linux/message/21403.

March 23, 2008, at 10:53 PM by J Brown --
March 23, 2008, at 10:52 PM by JBrown --
Changed lines 421-422 from:

as a lazy was to post photos online without creating thumbs.

to:

as a lazy way to post photos online without creating thumbs.

March 23, 2008, at 02:18 AM by JBrown --
Changed line 424 from:
to:

\\

March 23, 2008, at 02:15 AM by JBrown --
Changed lines 406-407 from:
  • -
to:

Changed lines 420-424 from:

I have added this php script: http://phpshow.panmental.de/ as a lazy was to post photos online without creating thumbs The performance is acceptable given the tiny footprint ~JBrown? 3-2008

to:

I have added this php script: http://phpshow.panmental.de as a lazy was to post photos online without creating thumbs.

The performance is acceptable given the tiny footprint.

JBrown? March 2008

March 23, 2008, at 02:03 AM by JBrown --
Added lines 406-424:
  • -

Certain Lighttpd versions (I'm using 1.4.18-3) have a bug when trying to access files >512kb it is documented here http://trac.lighttpd.net/trac/ticket/759

It basically says to add the following line to lighttpd.conf and restart the web server.

server.network-backend = "write"

I earlier tried running php with AppWeb? and Thttpd with no luck. Using Unslung 6.8 I installed Lighttpd/FCGI using the instructions above. The only change being that I moved the log files out of the webserver dir for security

I have added this php script: http://phpshow.panmental.de/ as a lazy was to post photos online without creating thumbs The performance is acceptable given the tiny footprint ~JBrown? 3-2008

March 19, 2008, at 10:05 AM by florent --
Added lines 55-57:

WARNING: the configuration has changed with Cherokee 0.6.0. Information below is outdated.

February 10, 2008, at 11:54 PM by fcarolo -- please report problems to the mailing list
Changed line 394 from:

i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected \\

to:

i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected'' \\

Changed lines 399-400 from:

Patrick February 2008'' -- Please use the mailing list to report problems and ask for help.

to:

Patrick February 2008

-- Please use the mailing list to report problems and ask for help.

February 10, 2008, at 11:53 PM by fcarolo -- please report problems to the mailing list
Changed lines 394-398 from:

i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected

anyone can help me? i am really new at this and feel totally lost

to:

i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected

anyone can help me?
i am really new at this and feel totally lost
\\

February 10, 2008, at 11:52 PM by fcarolo -- please report problems to the mailing list
Changed lines 391-393 from:

I am trying to set this up right now but can not get it working.

to:

''I am trying to set this up right now but can not get it working.

Changed lines 399-400 from:

Patrick February 2008

to:

Patrick February 2008'' -- Please use the mailing list to report problems and ask for help.

February 10, 2008, at 10:00 AM by patrick -- asking for help
Added lines 393-400:

I am trying to set this up right now but can not get it working. i created the php-test page but when i then launch php-fcgi nothing happens anymore i need to ctrl-c to get back to my promt, just running info.php on the slug gives me this error: ./info.php: ./info.php: 1: Syntax error: "(" unexpected

anyone can help me? i am really new at this and feel totally lost

Patrick February 2008

December 01, 2007, at 08:17 AM by jared hansen -- Minor tweak for grammar in intro paragraph
Changed lines 1-2 from:

FastCGI is a protocol between web application and web server. Because it offers much better performance than CGI, it is often used to deploy PHP web application on lightweight web servers that do not have a built-in mod_php.

to:

FastCGI is a protocol for interfacing between web applications and the web server. Because it offers much better performance than CGI, it is often used to deploy PHP web applications on lightweight web servers that do not have a built-in mod_php.

November 10, 2007, at 01:32 PM by case --
Changed lines 263-264 from:
  • Works well. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). Any solution to that?
to:
  • lighttpd-1.4.18ssl + php-fcgi 5.2.4 with eAccelerator v0.9.5.2 works well for me. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). My current solution is to use the externally spawned way as outlined below. (I just used user and group nobody, which is also what is used in lighttpd.conf. Only don't forget to chmod a+w your lighttpd logfiles also.) With PHP_FCGI_CHILDREN=2 this results in only 3 processes consuming my system memory. Will have to see if this compares well against using apache.
November 10, 2007, at 12:36 PM by case --
Added lines 262-264:
  • Works well. However, even though i use fcgi_children 4 as above, i get numerous instances of php-fcgi in ps (size 21348!). Any solution to that?
August 13, 2007, at 06:45 PM by RobHam -- Running the php-fcgi module in plane cgi mode with Lighttpd
Changed line 226 from:

It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuartion file as shown below.

to:

It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuration file as shown below.

August 13, 2007, at 06:42 PM by RobHam -- Running the php-fcgi module in plane cgi mode with Lighttpd
Changed lines 226-230 from:
  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.
to:

It is also possible to run the php-fcgi module in plane cgi mode with Lighttpd. Just add ".php" => "/opt/bin/php-fcgi" to the relevant section of the configuartion file as shown below.

Changed lines 230-237 from:

Extension php, php3, php4, php5 {

  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
to:

cgi.assign = ( ".pl" => "/opt/bin/perl",

                               ".php" => "/opt/bin/php-fcgi",
                               ".cgi" => "/opt/bin/perl" )
Added lines 236-253:
  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

June 21, 2007, at 10:23 AM by Rupert Plumridge -- just confirming a usefull hint, beneath Rob\'s hint
Added lines 247-252:
  • Prupertplum, I found that the hint from Rob was very usefull, plus, I also had to do the following:

Edit the configuration file: cherokee.conf in /opt/etc/cherokee so that the very end of the file reads:

Include /opt/etc/cherokee/sites-enabled/default

This finally got me from the 200 OK error to getting php files to run, yahay!

June 12, 2007, at 07:19 PM by RobHam -- PHP_FCGI_MAX_REQUESTS changed to 250, from experience a more appropriate value.
Changed line 171 from:
                          "socket" => "/home/mylogin/test-php/php-fcgi.sock",
to:
                          "socket" => "/tmp/php-fcgi.sock",
June 12, 2007, at 07:15 PM by RobHam -- PHP_FCGI_MAX_REQUESTS changed to 250, from experience a more appropriate value.
Changed lines 298-299 from:

PHP_FCGI_MAX_REQUESTS=200

to:

PHP_FCGI_MAX_REQUESTS=250

March 05, 2007, at 08:12 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI=]
Changed lines 298-299 from:

PHP_FCGI_MAX_REQUESTS=100

to:

PHP_FCGI_MAX_REQUESTS=200

March 04, 2007, at 11:00 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI =]
Changed line 262 from:
                       "max-procs" => 1,
to:
                       "max-procs" => 1
Changed lines 369-370 from:

The PHP_FCGI_CHILDREN setting should be set to max-procs + 1.

to:

The max-procs setting can be increased to run more server instances if needed. The PHP_FCGI_CHILDREN setting should also be increased to max-procs + 1.

March 04, 2007, at 10:44 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI =]
Changed lines 365-368 from:

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of user/group root will not work with a spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to set to the same using a command similar to chown -R www:everyone /opt/share/www

to:

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of USER/GROUP root will not work with externally spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to be set to the same using a command similar to chown -R www:everyone /opt/share/www

The PHP_FCGI_CHILDREN setting should be set to max-procs + 1.

March 04, 2007, at 09:39 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI=]
Changed lines 307-309 from:

USERID=nobody GROUPID=nobody

to:

USERID=www GROUPID=everyone

Added lines 363-368:

Notes :-

The PHP_FCGI_MAX_REQUESTS variable is deliberately set to a small value to improve server performance. Users may need to increase this a little but high values should be avoided.

The spawned PHP-FCGI process should run with the same USER and GROUP as your web server (the use of user/group root will not work with a spawned PHP-FCGI ) . The script assumes that a user www has been created for this purpose. Note that the owner and group settings of the web page files serviced by your web server will probably need to set to the same using a command similar to chown -R www:everyone /opt/share/www

March 04, 2007, at 09:04 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI=]
Changed lines 304-305 from:

ALLOWED_ENV="PATH USER"

to:

ALLOWED_ENV="PATH SHELL USER"

March 02, 2007, at 07:59 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI=]
Deleted line 262:
                       "idle-timeout" => 120,
March 02, 2007, at 07:51 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI=]
Changed lines 299-300 from:

PHP_FCGI_MAX_REQUESTS=200

to:

PHP_FCGI_MAX_REQUESTS=100

Changed line 354 from:
    sleep 2
to:
    sleep 3
March 01, 2007, at 10:44 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI=]
Changed line 171 from:
                          "socket" => "/home/mylogin/test-php/php-fastcgi.sock",
to:
                          "socket" => "/home/mylogin/test-php/php-fcgi.sock",
Changed lines 299-300 from:

PHP_FCGI_MAX_REQUESTS=1000

to:

PHP_FCGI_MAX_REQUESTS=200

Changed line 354 from:
    sleep 1
to:
    sleep 2
March 01, 2007, at 05:50 PM by RobHam -- Lighttpd using Externally spawned [=PHP-FCGI=]
Changed line 171 from:
                          "socket" => "/home/mylogin/test-php/php-fastcgi.socket",
to:
                          "socket" => "/home/mylogin/test-php/php-fastcgi.sock",
Changed lines 245-367 from:
  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
to:
  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!

Lighttpd with externally spawned PHP-FCGI

The current version of Lighttpd 1.4.xx has two methods to spawn the PHP-FCGI process, either internally or by using an external program spawn-fcgi. Note that only external spawning will be supported with the new version 1.5.xx when it is eventually released.

There are two steps needed to use externally spawned PHP-FCGI.

Firstly the Lighttpd config file needs to be amended as follows :-

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php-fcgi.sock",
                       "max-procs" => 1,
                       "idle-timeout" => 120,
                      )
                    )
                  )

(:tableend:)

Next, a start up script is needed to externally spawn the PHP-FCGI processes. The following script is based on one supplied with Lighttpd spawn-php.sh. Create an empty file using touch /opt/etc/init.d/S79php-fcgi then flag the file chmod 755 /opt/etc/init.d/S79php-fcgi

Add the following script section to the file using a Linux text editor.

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

 
#!/bin/sh
# /opt/etc/init.d/S79php-fcgi
#
# NSLU2 spawn-fcgi script for lighttpd
#
## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/opt/bin/spawn-fcgi"

## ABSOLUTE path to the PHP-FCGI binary
FCGIPROGRAM="/opt/bin/php-fcgi"

## ABSOLUTE path and name of PID-file for spawed process
FCGIPID="/opt/var/run/php-fcgi.pid"

## TCP port or socket to bind to
FCGISOCKET="/tmp/php-fcgi.sock"
# FCGIPORT="1026"

## number of PHP children to spawn (min 2)
PHP_FCGI_CHILDREN=2

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=1000

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.1.77"

## Allowed environment variables, separated by spaces
ALLOWED_ENV="PATH USER"

## user and group to run PHP-FCGI
USERID=nobody
GROUPID=nobody

################## no config below this line

if [ -z "$1" ] ; then
  case `echo "$0" | /bin/sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
  esac
else
  rc="$1"
fi

case "$rc" in
  start)
    echo -n "Starting PHP-FCGI: "
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    if [ -n "$FCGISOCKET" ]; then
      EX="$SPAWNFCGI -s $FCGISOCKET -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    elif [ -n "$FCGIPORT" ]; then
      EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -P $FCGIPID -C $PHP_FCGI_CHILDREN -u $USERID -g $GROUPID"
    else
      echo "- ERROR - socket or port must be specified!"
      exit 0
    fi
    E=
    for i in $ALLOWED_ENV; do
      eval "x=\$$i"
      E="$E $i=$x"
    done
    env - $E $EX
    echo ok
      ;;
  stop)
    if [ -n "`pidof php-fcgi`" ]; then
      echo -n "Stopping PHP-FCGI: "
      killall php-fcgi 2> /dev/null
      echo ok
    fi
      ;;
  restart)
    "$0" stop
    sleep 1
    "$0" start
      ;;
  *)  
    echo "Usage: $0 (start|stop|restart|usage)"
      ;;
esac

(:tableend:)

RobHam - March 2007

January 11, 2007, at 07:52 PM by Marc -- Added installation of libstdc++
Changed lines 10-11 from:
  1. ipkg install php php-fcgi @]
to:
  1. ipkg install php php-fcgi
  2. ipkg install libstdc++ @]
January 11, 2007, at 03:20 PM by Crazyman --
Changed line 244 from:
  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.1.6, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
to:
  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.2.0, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
November 23, 2006, at 09:28 PM by BrianZhou --
Changed line 244 from:
  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.1.6, SQLite? and Lighttpd 1.4.13. Works like a charm with the config file from above!
to:
  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.1.6, SQLite and Lighttpd 1.4.13. Works like a charm with the config file from above!
November 23, 2006, at 12:38 PM by crazyman --
Changed line 244 from:
  • Crazyman, I use: Unslung 6.8, php/php-fcgi 5.1.6, SQLite? and Lighttpd 1.4.13. Works like a charm with the config file from above!
to:
  • Crazyman - I use: Unslung 6.8, php/php-fcgi 5.1.6, SQLite? and Lighttpd 1.4.13. Works like a charm with the config file from above!
November 23, 2006, at 12:36 PM by crazyman --
Added line 244:
  • Crazyman, I use: Unslung 6.8, php/php-fcgi 5.1.6, SQLite? and Lighttpd 1.4.13. Works like a charm with the config file from above!
May 10, 2006, at 05:21 PM by rvanderh3 --
Changed lines 226-227 from:
  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead.
to:
  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead. I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.
Deleted lines 243-244:

I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

May 10, 2006, at 05:20 PM by rvanderh3 --
Changed lines 226-228 from:
  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1

I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead.

to:
  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1. I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead.
May 10, 2006, at 05:18 PM by rvanderh3 --
Added lines 225-244:
  • rvanderh3 unslung 6.8, cherokee, php/php-fcgi/php-mysql 5.1.4.1

I had some trouble to get php-cfgi to work. First of all I mixed an older version of php (5.0.x) with php-fcgi and php-mysql (5.1.4.1) which causes php not accepting mysql code. The code of cherokee.conf above didn't work out for me. Thanks to Janne5011 I found out that I had to leave the original untouched and put the next code into /opt/etc/cherokee/sites-available in stead.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
  Handler fcgi {
     Server localhost:8002 {
        Env PHP_FCGI_MAX_REQUESTS "4000"
        Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
     }
  }
}

(:tableend:)

I was glad I get php en mysql to work this way. But it still is very slow, although (much ?) quicker then under apache.

May 09, 2006, at 10:02 PM by RobHam -- Note added regarding running php-fcgi with cherokee in plane cgi mode
Changed lines 167-176 from:

fastcgi.server = ( ".php" =>

                               ( "localhost" =>
                                 (
                                   "socket" => "/home/mylogin/test-php/php-fastcgi.socket",
                                   "bin-path" => "/opt/bin/php-fcgi",
                                   "bin-environment" => (
                                        "PHP_FCGI_CHILDREN" => "4",
                                        "PHP_FCGI_MAX_REQUESTS" => "4000"
                                   )
                                 )
to:

fastcgi.server = ( ".php" =>

                      ( "localhost" =>
                        (
                          "socket" => "/home/mylogin/test-php/php-fastcgi.socket",
                          "bin-path" => "/opt/bin/php-fcgi",
                          "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "4000"
Changed lines 176-178 from:
                            )
to:
                             )
                           )
                        )
Changed lines 211-213 from:
  • Brian.Zhou lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
to:
  • Brian.Zhou - lighttpd and cherokee optware ipkg on TurboSlug, simple test pages
  • Janne5011 - cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
  • RobHam - cherokee, php php-fcgi, Unslung 5.5 and Mysql and Imagemagik needed to run Gallery2. My experience is that web pages seem to load very slowly when running php-fcgi in fcgi mode as described above so have reverted back to plane cgi mode. Some changes are needed to the relevant part of the cherokee config script. Running in cgi mode will allow the php-fcgi executable to be automaticaly removed from memory when not needed hence freeing up memory for other program tasks.

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Extension php, php3, php4, php5 {
        Handler phpcgi {
                        Interpreter /opt/bin/php-fcgi 
        }
}

(:tableend:)

May 07, 2006, at 01:26 AM by janne5011 --
Added lines 212-213:
  • Janne5011 cherokee,php php-fcgi, Unslung 6.8. I simply replaced my cherokee.conf with the provided above and wrote "/opt/sbin/cherokee -C". Easy =)
May 04, 2006, at 11:39 PM by Brian Zhou --
Changed line 211 from:
  • Brian.Zhou lighttpd and cherokee optware ipkg on slug, simple test pages
to:
May 04, 2006, at 11:39 PM by Brian Zhou --
Changed line 211 from:
  • Brian.Zhou? lighttpd and cherokee optware ipkg on slug, simple test pages
to:
  • Brian.Zhou lighttpd and cherokee optware ipkg on slug, simple test pages
May 04, 2006, at 11:37 PM by Brian Zhou --
Changed line 211 from:
  • BrianZhou? lighttpd and cherokee optware ipkg on slug, simple test pages
to:
  • Brian.Zhou? lighttpd and cherokee optware ipkg on slug, simple test pages
May 04, 2006, at 11:37 PM by Brian Zhou -- added up&running list
Changed lines 204-211 from:
  • php-fastcgi config with it's own php.ini
to:
  • php-fastcgi config with it's own php.ini

Up and Running

Let other people know that you successfully use the above procedure to run PHP apps:

  • BrianZhou? lighttpd and cherokee optware ipkg on slug, simple test pages
April 14, 2006, at 03:37 PM by BrianZhou --
Changed lines 3-4 from:

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following content.

to:

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following file content.

Added lines 24-30:

Launch php-fcgi command. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/bin/php-fcgi 

(:tableend:)

April 13, 2006, at 04:04 AM by BrianZhou --
Changed lines 3-4 from:

The example below is on unslung firmware and using optware packages.

to:

The example below is on unslung firmware and using optware packages. Whenever you see cat filename, it means you need to use editor to create filename with the corresponding conent, so that when you type cat filename, you will see the following content.

March 27, 2006, at 06:57 AM by BrianZhou --
Changed lines 192-197 from:

(:tableend:)

to:

(:tableend:)


References:

  • lighttpd FastCGI module
  • php-fastcgi config with it's own php.ini
March 27, 2006, at 04:36 AM by bzhou -- php-fcgi in the feed now
Deleted lines 12-13:

Note, php-fcgi is currently waiting to be promoted.

March 26, 2006, at 05:53 PM by BrianZhou --
Changed line 6 from:

Install PHP & ```php-fcgi``` packages

to:

Install PHP & php-fcgi packages

March 26, 2006, at 07:14 AM by BrianZhou --
Deleted line 86:

server.c:843: WARNING: Unable to set file descriptor limit to 16384

March 26, 2006, at 06:21 AM by BrianZhou --
Changed line 70 from:
  Handler fastcgi {
to:
  Handler fcgi {
March 26, 2006, at 05:30 AM by BrianZhou --
Changed line 182 from:

$ /opt/sbin/lighttpd -D -f ~/test-scgi/lighttpd-scgi.conf @]

to:

$ /opt/sbin/lighttpd -D -f ~/test-php/lighttpd-php.conf @]

March 26, 2006, at 05:29 AM by BrianZhou --
Changed lines 6-8 from:

Install a web server with FastCGI support

Install lighttpd

to:

Install PHP & ```php-fcgi``` packages

Changed line 10 from:
  1. ipkg install lighttpd @]
to:
  1. ipkg install php php-fcgi @]
Changed lines 13-15 from:

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

to:

Note, php-fcgi is currently waiting to be promoted.


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

Changed lines 20-23 from:
  1. ipkg install cherokee@]
to:

$ cat ~/test-php/info.php@] (:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 
Deleted lines 25-26:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

Changed lines 27-31 from:

Configure the web server

cherokee

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

to:

Install a web server with FastCGI support

Install lighttpd

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

Changed lines 33-34 from:

$ cat ~/test-php/cherokee-php.conf @] (:cellnr bgcolor=#eeeeee:)

to:
  1. ipkg install lighttpd @]

(:tableend:)

Or, install cherokee

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

Added lines 40-54:
  1. ipkg install cherokee@]

(:tableend:)

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.


Configure & launching the web server

cherokee

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:) [@

Changed line 93 from:

Configure lighttpd

to:

Or lighttpd

Changed lines 178-181 from:

Install PHP packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

to:

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Changed line 182 from:
  1. ipkg install php php-fcgi @]
to:

$ /opt/sbin/lighttpd -D -f ~/test-scgi/lighttpd-scgi.conf @]

Changed lines 184-185 from:

A PHP test page

to:

Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

Changed line 189 from:

(:cell bgcolor=#eeffee:)

to:

(:cellnr bgcolor=#eeffee:)

Changed lines 191-192 from:

$ cat ~/public_html/info.php@] (:cellnr bgcolor=#eeeeee:)

to:

$ w3m -dump http://localhost:8081/info.php | less @] (:cellnr bgcolor=#eeffee:)

Deleted lines 193-204:

<?php phpinfo(); ?> @] (:tableend:)


Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:cellnr bgcolor=#eeffee:) [@

March 26, 2006, at 05:23 AM by BrianZhou --
Changed lines 1-2 from:

FastCGI is a protocol between web application and web server. Because it offers much much better performance than CGI, it is often used to deploy PHP web application on lightweight web servers that do not have a built-in mod_php.

to:

FastCGI is a protocol between web application and web server. Because it offers much better performance than CGI, it is often used to deploy PHP web application on lightweight web servers that do not have a built-in mod_php.

Changed lines 22-23 from:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

to:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

Added lines 34-47:

Port 8082 IPv6? Off Timeout 60 KeepAlive? On MaxKeepAliveRequests? 500 ServerTokens? Full PidFile? /home/mylogin/tmp/cherokee.pid Icons /opt/etc/cherokee/icons.conf MimeFile? /opt/etc/cherokee/mime.types MimeFile? /opt/etc/cherokee/mime.compression.types Include /opt/etc/cherokee/advanced.conf Include /opt/etc/cherokee/mods-enabled Documentroot /home/mylogin/test-php DirectoryIndex? index.html

Changed lines 51-53 from:
      Env PHP_FCGI_MAX_REQUESTS "5000"
      Env PHP_FCGI_CHILDREN "5"
        Interpreter "/opt/lib/cgi-bin/php5-fcgi -b 8002"
to:
      Env PHP_FCGI_MAX_REQUESTS "4000"
      Env PHP_FCGI_CHILDREN "4"
        Interpreter "/opt/bin/php-fcgi -b 8002"
March 26, 2006, at 05:19 AM by BrianZhou --
Changed line 27 from:

Configure lighttpd

to:

cherokee

Changed line 31 from:

$ cat ~/test-scgi/lighttpd-scgi.conf @]

to:

$ cat ~/test-php/cherokee-php.conf @]

Added lines 34-64:

Extension php, php3, php4, php5 {

  Handler fastcgi {
    Server localhost:8002 {
      Env PHP_FCGI_MAX_REQUESTS "5000"
      Env PHP_FCGI_CHILDREN "5"
        Interpreter "/opt/lib/cgi-bin/php5-fcgi -b 8002"
    }
  }

}@] (:tableend:)

Launch it. (:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ /opt/sbin/cherokee -C ~/test-php/cherokee-php.conf 

(:cellnr bgcolor=#eeeeee:)

server.c:843: WARNING: Unable to set file descriptor limit to 16384
Cherokee Web Server 0.4.31b18: Listening on port 8083, TLS disabled
 IPv6 disable, using poll, 1024 fds limit, 5 threads, 204 fds in each
 standard scheduling policy

(:tableend:)

Configure lighttpd

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ cat ~/test-php/lighttpd-php.conf 

(:cellnr bgcolor=#eeeeee:) [@

Deleted lines 142-143:

Or, configure cherokee

Added lines 168-170:

(:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8082/info.php | less 
March 26, 2006, at 04:56 AM by BrianZhou --
Changed lines 6-7 from:

Install a web server with FastCGI support

to:

Install a web server with FastCGI support

Changed lines 28-34 from:

Or, configure cherokee


Install PHP packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

to:

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

Changed lines 31-36 from:
  1. ipkg install php php-fcgi @]

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

to:

$ cat ~/test-scgi/lighttpd-scgi.conf @] (:cellnr bgcolor=#eeeeee:)

Changed lines 34-39 from:

$ cat ~/public_html/info.php@] (:cellnr bgcolor=#eeeeee:)

<?php
phpinfo();
?> 
to:

server.port = 8081 server.modules = (

                                "mod_access",
                                "mod_fastcgi",
                                "mod_accesslog" )

server.document-root = "/home/mylogin/test-php" server.errorlog = "/home/mylogin/test-php/error.log" accesslog.filename = "/home/mylogin/test-php/access.log" index-file.names = ( "index.php", "index.html",

                                "index.htm", "default.htm" )

mimetype.assign = (

  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )

fastcgi.server = ( ".php" =>

                               ( "localhost" =>
                                 (
                                   "socket" => "/home/mylogin/test-php/php-fastcgi.socket",
                                   "bin-path" => "/opt/bin/php-fcgi",
                                   "bin-environment" => (
                                        "PHP_FCGI_CHILDREN" => "4",
                                        "PHP_FCGI_MAX_REQUESTS" => "4000"
                                   )
                                 )
                               )
                            )

@]

Added lines 111-113:

Or, configure cherokee

Changed lines 115-139 from:

Test

to:

Install PHP packages

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

# ipkg install php php-fcgi 

(:tableend:)


A PHP test page

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

$ cat ~/public_html/info.php

(:cellnr bgcolor=#eeeeee:)

<?php phpinfo(); ?> 

(:tableend:)


Test

Here I'm using w3m as web browser, you can also use elinks, or any graphic browser on a different machine (adjust the URL correspondingly).

(:table border=0 width=80%:) (:cellnr bgcolor=#eeffee:)

$ w3m -dump http://localhost:8081/info.php | less 

(:tableend:)

March 26, 2006, at 02:48 AM by bzhou --
Added line 45:

[@

March 26, 2006, at 02:47 AM by bzhou --
Changed lines 40-41 from:

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

to:

(:table border=0 width=80%:) (:cell bgcolor=#eeffee:)

Changed lines 43-44 from:

$ cat ~/public_html/info.php

to:

$ cat ~/public_html/info.php@] (:cellnr bgcolor=#eeeeee:)

March 26, 2006, at 01:13 AM by bzhou --
Changed line 12 from:

ipkg install lighttpd @]

to:
  1. ipkg install lighttpd @]
Changed line 19 from:

ipkg install cherokee@]

to:
  1. ipkg install cherokee@]
Changed line 36 from:

ipkg install php php-fcgi @]

to:
  1. ipkg install php php-fcgi @]
March 26, 2006, at 01:12 AM by bzhou --
Changed lines 21-22 from:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

to:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

Changed lines 40-47 from:
to:

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

$ cat ~/public_html/info.php
<?php
phpinfo();
?> 

(:tableend:)

March 26, 2006, at 01:04 AM by bzhou --
Changed lines 6-7 from:

Install a web server with FastCGI support

to:

Install a web server with FastCGI support

Changed lines 32-36 from:
to:

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

ipkg install php php-fcgi 

(:tableend:)

March 26, 2006, at 01:03 AM by bzhou --
Changed lines 21-22 from:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI? problems. Version earlier than this probably does not work.

to:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI problems. Version earlier than this probably does not work.

March 26, 2006, at 01:01 AM by bzhou --
Changed lines 21-22 from:
to:

Please note cherokee 0.4.31b18 fixed a couple of SCGI/FastCGI? problems. Version earlier than this probably does not work.

March 26, 2006, at 12:54 AM by bzhou --
Changed lines 12-13 from:

ipkg install lighttpd @]

to:

ipkg install lighttpd @]

Changed lines 19-20 from:

ipkg install cherokee @]

to:

ipkg install cherokee@]

March 26, 2006, at 12:54 AM by bzhou --
Changed lines 9-10 from:

(:table border=0 width=80% bgcolor=#eeffee:)(:cell:)

to:

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

Changed lines 17-18 from:

(:table border=0 width=80% bgcolor=#eeffee:)(:cell:)

to:

(:table border=0 width=80% bgcolor=#eeffee:) (:cell:)

March 26, 2006, at 12:53 AM by bzhou --
Changed lines 9-14 from:
to:

(:table border=0 width=80% bgcolor=#eeffee:)(:cell:)

ipkg install lighttpd

(:tableend:)

Changed lines 16-21 from:
to:

(:table border=0 width=80% bgcolor=#eeffee:)(:cell:)

ipkg install cherokee

(:tableend:)

March 26, 2006, at 12:46 AM by bzhou -- initial version
Added lines 1-26:

FastCGI is a protocol between web application and web server. Because it offers much much better performance than CGI, it is often used to deploy PHP web application on lightweight web servers that do not have a built-in mod_php.

The example below is on unslung firmware and using optware packages.


Install a web server with FastCGI support

Install lighttpd

Or, install cherokee


Configure the web server

Configure lighttpd

Or, configure cherokee


Install PHP packages


A PHP test page


Test