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

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

For example:

Task: Map html to php = ( ".html" => ".php" )

Task: Map old .php3 files to php = ( ".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: = ( ".html" => ".php" )

At the end your configuration should look like as follows (your fastcgi directives may look little different): = ( ".html" => ".php" )
fastcgi.server = ( ".php" =>
"bin-path" => "/usr/bin/php",
"socket" => "/tmp/php.socket",
"max-procs" => 2,
"idle-timeout" => 20,
"bin-environment" => (
"bin-copy-environment" => (
"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!

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • sagar Oct 23, 2006 @ 22:39

    thanks for tip. it is working now.

  • sandhya rana Mar 7, 2007 @ 5:25

    please tell the way of execute html(steps)

  • sandhya rana Mar 7, 2007 @ 5:26

    please tell the way of run html steps

  • Pacco Mar 22, 2010 @ 22:31

    Can you map xml the same way to php?
    I’m trying to configure RSS feed to work with lighttpd. It works fine with Apache.

  • Asish Satpathy Jun 5, 2010 @ 1:25

    How can i execute a html files in linux especially in fedora 9.
    Please give me the solution as soon as possible.

  • david Jun 1, 2014 @ 15:18

    Thanks for posting this 8 years ago 🙂 still helpfull

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum