Lighttpd is an easy, fast, and flexible web-server that runs on low-resources (CPU/RAM) while running on a small server. In this tutorial, I will show how to configure lighttpd with PHP to work on multiple sub-domains by using virtual hosts.
These steps were tested on an Ubuntu Server.
Update the server to the latest packages/updates.
apt-get updateInstall lighttpd and PHP.
sudo apt-get install lighttpd php5-cgiEnable the fastcgi module and FastCGI PHP support.
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-phpRestart your lighttpd service to apply the FastCGI changes.
sudo service lighttpd force-reloadOn your server, edit the /etc/lighttpd/lighttpd.conf file. Some admins prefer uploading a configuration file over FTP instead of SSH editing.
vi /etc/lighttpd/lighttpd.conf By default, the document root is /var/www. You may prefer to host your sites in a different folder, such as /var/websites.
#change
server.document-root = "/var/www"
#to
server.document-root = "/var/websites/root"Note that lighttpd disables the directory listing by default.
Add the following to lighttpd.conf host a domain or subdomain.
$HTTP["host"] =~ "^mydomain\.com$" {
server.document-root = "/var/websites/domain"
}
#or
$HTTP["host"] =~ "^sub\.mydomain\.com$" {
server.document-root = "/var/websites/domain/sub"
}Bear in mind that the $HTTP line contains a regular expression between quotation marks.
If you would like to disable directory listings for virtual hosts, use the following example.
$HTTP["host"] =~ "^sub\.mydomain\.com$" {
server.document-root = "/var/websites/domain/sub"
dir-listing.activate = "disable"
} Once you have finished adding virtual hosts, save the lighttpd.conf file and restart the lighttpd service.
service lighttpd restartAt this point, lighttpd it is serving your PHP pages. Enjoy!