FastCGI is a language independent, scalable, open extension to CGI that provides high performance without the limitations of server specific APIs. FastCGI provides better scalability and performance. Instead of creating a new process (the CGI program) for every request, FastCGI uses a single persistent process which handles many requests over its lifetime. (See wikipedia article for more information)
Make sure php support fastcgi
Type any one of the following command to verify that php support fastcgi
$ php -v
Output:
PHP 5.0.4 (cli) (built: Nov 8 2005 08:27:12) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
OR
$ php-cgi -v
Output:
PHP 5.0.4 (cgi-fcgi) (built: Nov 8 2005 08:25:54) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
You must get string cgi-fcgi. Next find out full path to php-cgi or php binary:
$ which php-cgi
Output:
/usr/bin/php-cgi
Open lighttpd configuration file:
# vi /etc/lighttpd/lighttpd.conf
First add the module mod_fastcgi (lighttpd provides an interface to a external programs that support the FastCGI interface via this module). Make sure your server.modules loades mod_fastcgi:
server.modules = (
"mod_access",
"mod_accesslog",
"mod_fastcgi",
"mod_rewrite",
"mod_auth"
)Now add following lines to configuration:
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
)))
Save the configuration and close all the files. Restart the lighttpd:
# /etc/init.d/lighttpd restart
Test your configuration by running php program or application.
See also
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop











{ 20 comments… read them below or add one }
There is an typo in:
fastcgi.server = ( “.php” => ((“bin-path” => “/usr/bin/php-cgi”,
“socket” => “/tmp/php.socket”,
)))
the last “,” is actually causing issues.
Pierre,
Thanks for the heads up. Post has been updated…
Hi,
I get the next error when I try to start lighttpd
Starting web server: lighttpd2007-07-16 21:43:23: (configfile.c.827) source: /etc/lighttpd/lighttpd.conf line: 164 pos: 31 parser failed somehow near here: socket
failed!
The line 146 is the socket configuration for php.
Any ideas????
It works!
I write the solution:
server.modules += ( “mod_fastcgi” )
fastcgi.server = ( “.php” =>
((
“bin-path” => “/usr/bin/php4-cgi”,
“socket” => “/tmp/php.socket”,
“max-procs” => 2,
“idle-timeout” => 20,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “4″,
“PHP_FCGI_MAX_REQUESTS” => “10000″
),
“bin-copy-environment” => (
“PATH”, “SHELL”, “USER”
),
“broken-scriptfilename” => “enable”
))
)
You also need to create the log dir and the socket file dir, otherwise, the server can not be started
Starting lighttpd: 2007-12-27 14:26:03: (plugin.c.165) dlopen() failed for: /usr/lib/lighttpd/mod_fastcgi.so /usr/lib/lighttpd/mod_fastcgi.so: undefined symbol: ltostr
2007-12-27 14:26:03: (server.c.621) loading plugins finally failed
[FAILED]
i am unable to start it
mayank: what OS are you running ?
you need to install lighttpd-fastcgi,
redhat/fedora/centos
# yum install lighttpd-fastcgi
for ubuntu it’s
apt-get install php5-cgi
Sir
My server with lighttpd is working good and scripts are also running but they are not been abel to connect to there respective databases .Hense I am still on Apache . Please figure it out for me if you can.
Thanks.
I would like to set up a configuration just using CGI rather than fastcgi.
how should i set the configure file for it. thx
Hi,
I want to have multiple php error_log files without using different php.ini files.
Any ideas ?
Thanks
I’ve read, that it is recommended to set PHP_FCGI_MAX_REQUESTS to something like 500.
I wonder how to enable fast-cgi for pages with html extension?!
Hi, I wanted to install Lighttpd with PHP support on my Fedora 12 VM. However, I don’t have access to the internet on the VMware station neither do I have yum installed. Any suggestions on how I could install Lighttpd with PHP support?
Thanks a lot!
Dud, It’s Perfect!Everthing goes fine here! Tanks a lot!
It worked on Debian 6, lighttpd 1.4.28, PHP 5.3.6
Thanks!
On Ubuntu (and probably Debian too as I bet it’s the same package), you don’t need to add that stuff manually to lighttpd.conf anymore.
To get php running with lighttpd, you can just do:
apt-get install lighttpd php5-cgi && lighttpd-enable-mod && service lighttpd restart
You save my day. Thanks.
Would have been perfect if instructions for running php in .html or .htm files were included…
Big thanks, the solution You have provided works perfectly.