You are reading

Running php-fcgi independently from Lighttpd

Posted: June 9, 2009 | By: TJ | In Technology | 2 comments

As of Lighttpd 1.4.x, the spawn-fcgi binary is included in the package when you install Lighttpd. When Lighttpd starts, it will launch php-cgi processes under Lighttpd defined by the fastcgi.server value in the lighttpd.conf. The problem is that when you need to restart Lighttpd, the FastCGI processes don’t die. This also makes it difficult to monitor php-cgi as a service because it does not have a pid file. The solution is to remove spawn-fcgi and proxy all requests to a php-fastcgi daemon to keep it independent of Lighttpd altogether.

The first step was to create a php-fcgi default file, /etc/default/php-fcgi:

START=yes
EXEC_AS_USER=www-data
FCGI_HOST=localhost
FCGI_PORT=9000
PHP_FCGI_CHILDREN=2
PHP_FCGI_MAX_REQUESTS=1000

Once this file has been created, now we want to make sure that php-fcgi starts when the server starts:

$ update-rc.d php-fcgi defaults

Now, edit the lighttpd.conf to proxy all php requests to port 9000:

fastcgi.server = (
".php" => (
( "host" => "127.0.0.1",
"port" => 9000,
"max-procs" => 1,
"idle-timeout" => 15,
"broken-scriptfilename" => "enable" )))

You’ll then need to create an init script so you can control the daemon. I’ve included mine to view.

Make the script executable:

$ chmod +x /etc/init.d/php-fcgi

Force reload the new Lighttpd configuration and kill any running php processes running from the prior http configuration:

$ /etc/init.d/lighttpd force-reload

Now, start php-fcgi:

$ /etc/init.d/php-fcgi

Comments for this entry

How do you know if its using memcache rather than files?

How do you know if its using memcache rather than files? When I set the session save path and the other part of it, it asks me to download the files. What’s wrong?

The easiest way is to tail the memcached.log. If you’ve set up verbose logging, you can watch the sessions being logged as they happen. Using something like:

$ tail -f /var/log/memecached.log

Karan

Thanks for the article, however, I get the following error when i try to run the make command: http://pastie.org/private/ndnoqi2defntxouhshtona

Any ideas? Thanks again :)

[...] is a rehash of this tutorial but for Debian [...]

[...] http://longvnit.com/blog/?p=627 http://constantshift.com/installing-apc-for-php-5-3/ CentOS 5 – PHP SSH2CentOS – soporte PHP FFMPEGCentOS 5 – Php Zend y Sql [...]

Leave your comment



Copyright © 2010. All rights reserved.

This blog is powered by WordPress and proudly hosted by (mt) Media Temple.