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 Ubuntu server.
Update the server to the latest packages/updates.
apt-get update
Install lighttpd and PHP.
sudo apt-get install lighttpd php5-cgi
Enable the fastcgi module and fastcgi PHP support.
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
Restart your lighttpd service to apply the fastcgi changes.
sudo service lighttpd force-reload
On 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 out of 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
to 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"
}
Bare 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 restart
At this point, lighttpd is serving your PHP pages. Enjoy!