PHP on Lighttpd
Also see Optimizing PHP with Lighttpd for tips on optimizing your PHP configuration.
I’ve created this page to detail how I got my PHP files to parse successfully under lighttpd. Your situation might be totally different than mine, but I hope it’ll provide some insight.
Without configuration, lighttpd doesn’t know what to do with .php files. Instead of serving them as parsed code, lighty will try to serve them as binary file downloads. This isn’t what you want. (duh)
What you need to do is add some code to your lighttpd.conf file to initiate php when your lighty server launches. I’ve included my basic code below. The FastCGI documentation has a lot of detailed instructions about Starting a FastCGI-PHP Process. It’s not as thorough or easy to understand as it could be, but it should get you started.
PHP & SCGI
My current lighttpd.conf is running .scgi rather than the more common .fcgi (courtesy of dgibbons?). Unfortunately, there’s no direct way to have .scgi and .php play together (that I’m aware of), so you have to add a fastcgi entry specifically for the PHP.
Note: I couldn’t get this to work in the $HOST{} entries, but it’s working fine outside of them. Just stick it above or below your $HOST entries (outside of the brackets!) just like your default .server entries.
Here’s the code that works for me:
fastcgi.server = ( ".php" => ((
"socket" => "/home/*username*/*domain.xyz*/php-fastcgi.socket",
"bin-path" => "/usr/local/php5/bin/php",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000" ),
"bin-copy-environment" => (
"PATH", "SHELL", "USER" ),
"broken-scriptfilename" => "enable"
)) )
Note: this is an unoptimized config and will create an unecessarily large number of PHP processes (68 in total). Once you have your PHP config working, make sure you read Optimizing PHP with Lighttpd in order to bring the number of processes down. You want to play nice with other people on the server, after all.
Additional Configuration
There’s more details on the FastCGI website about spawning and other advanced features that exceed my skillset. If you can expand on these features, please update the wiki! :)