Install Lighttpd and PHP on Ubuntu

  • Last Created On Dec 08, 2024
  • 11
0 0

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.

Install software

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

Configure your website

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
Setup the document root

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 virtual hosts

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"
}
Save and restart

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!

Views: 11

Recent Articles

  • How to Install JAX with ROCm Acceleratio...
    96
  • Deploy a PyTorch Workspace on a Vultr Cl...
    71
  • Managing Backup Storage
    83
  • Automating FTP Backups in Windows Server
    71
  • Automating FTP Backups in Linux
    75

Popular Articles

  • Our General Terms & Conditions
    2632
  • Our Privacy Policy
    2478
  • Our Cookies Policy
    275
  • Our Terms of Use
    153
  • How to Install JAX with ROCm Acceleratio...
    96