Lighttpd map html pages to php (execute html pages as php)

Posted on in Categories lighttpd, Tips, Troubleshooting last updated October 23, 2006
Lighttpd logo

Sometime you need to run old html file(s) as php pages, especially if you are migrating from Apache web server. To treat html pages as php you need to map multiple extensions to the same fastcgi server using fastcgi.map-extensions directive.

For example:

Task: Map html to php

fastcgi.map-extensions = ( ".html" => ".php" )

Task: Map old .php3 files to php

fastcgi.map-extensions = ( ".php3" => ".php" )

However, when you map .html file you need to disable mod_compress which does output compression and reduces the network load. It can improve the overall throughput of the webserver. This module by default compress .html file. You have two choices:
a) Remove the module
b) Skip .html files from (mod_compress)

Open Lightttpd configuration file:
# vi /etc/lighttpd/lighttpd.conf
Find out compress.cache-dir and compress.filetype directive and comment out (or remove the lines):
# compress.cache-dir = "/tmp/lighttpd/cache/compress/"
# compress.filetype = ("text/plain", "text/html")

Next, find out mod_compress server.modules line and comment out the same.

Next map .html extension by adding the directive:
fastcgi.map-extensions = ( ".html" => ".php" )

At the end your configuration should look like as follows (your fastcgi directives may look little different):
fastcgi.map-extensions = ( ".html" => ".php" )
fastcgi.server = ( ".php" =>
((
"bin-path" => "/usr/bin/php",
"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"
))
)

Save and close the file. Restart lighttpd server:
# /etc/init.d/lighttpd restart

It took 30+ minutes to solve this small problem. Finally following command gave me back answer:
$ lynx http://localhost/test.html

It was downloading test.html as .gz file. I immediately realized that sever is compressing files (test.html) using mod_compress and then transmitting file to client. So I disabled the mod_comress, restarted the server and voila!

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

6 comment

Leave a Comment