Debianhelp.co.uk


PHP and PHP Fastcgi Configuration in Lighttpd

Introduction

Lighttpd supports PHP through both CGI and FastCGI. As the name suggests, FastCGI is preferable.

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.

Performance

In all our tests it has shown better performance than Apache 1.3.x + mod_php4. See http://www.lighttpd.net/benchmark/ for the results.

Does it support opcode cachers like APC, TurckMM, XCache and friends?

YES! Even if their docs say they do not work in CGI. Under lighttpd, PHP is usually run as FastCGI which supports those opcode cachers like mod_php4 in Apache.

http://pear.php.net/apc
http://eaccelerator.net/ (Successor of Turck mmCache)
XCache, Installing XCache (new, well tested, running with FastCGI)

Installing PHP and FasiCGI in Debian

#apt-get install php4 php4-cgi

This will complete the installation of PHP and FastCGI supported files

Now you need to find the exact versions are installed or not using the following commands

# php -v

# php-cgi -v

You must get string cgi-fcgi. Next find out full path to php-cgi:

# which php-cgi

/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.

If you want more configuration Options for Fastcgi check here

Restart the lighttpd:

# /etc/init.d/lighttpd restart

Test your configuration by running php program or application.

Main Source of article can be found here