How to Install and Configure the Lighttpd Web Server on Ubuntu

What is Lighttpd?

While Apache and Nginx dominate the web server market, they can be resource-heavy for low-end hardware. Lighttpd (pronounced “lighty”) is an open-source, secure, and incredibly fast web server designed specifically for environments suffering from severe memory and CPU constraints. It is the perfect choice for serving static content, running on a Raspberry Pi, or deploying lightweight web applications on a cheap VPS.

Step 1: Install the Lighttpd Package

Lighttpd is available in the default Ubuntu package repositories. First, ensure your system is up to date, then install the package:

sudo apt update

sudo apt install lighttpd -y

Upon installation, the service will automatically start. You can verify it is running by navigating to your server’s IP address in a web browser; you should see the default “Lighttpd Placeholder page”.

Step 2: Understand the File Structure

Before configuring the server, you should familiarize yourself with its default directory structure:

  • /etc/lighttpd/lighttpd.conf: The main configuration file.
  • /etc/lighttpd/conf-available/: Contains configuration files for modules (like PHP or SSL) that are not yet enabled.
  • /etc/lighttpd/conf-enabled/: Contains symlinks to the modules that are actively running.
  • /var/www/html/: The default document root where your website files (HTML, CSS, JS) should be stored.

Step 3: Enable PHP Support (FastCGI)

If you plan to run dynamic applications (like a lightweight blog), you will need to enable PHP processing. Lighttpd uses FastCGI to interface with PHP. First, install the PHP FastCGI Process Manager:

sudo apt install php-fpm -y

Next, use the built-in lighty-enable-mod script to easily activate the FastCGI and FastCGI-PHP modules:

sudo lighty-enable-mod fastcgi

sudo lighty-enable-mod fastcgi-php

Step 4: Reload the Configuration

Any time you enable a module or manually edit the lighttpd.conf file, you must reload the service for the changes to take effect:

sudo systemctl force-reload lighttpd

Step 5: Test the PHP Processor

To verify that Lighttpd is successfully handing off PHP files to the PHP-FPM processor, create a temporary info.php file in your document root:

sudo nano /var/www/html/info.php

Add the following PHP code, which outputs server environment details:

<?php phpinfo(); ?>

Save and close the file. Navigate to http://your-server-ip/info.php in your web browser. If you see the purple PHP configuration page rather than raw code, your Lighttpd web server is fully operational and ready to host your dynamic web applications.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.