How to install & configure Lighttpd web server on Ubuntu 20.04 LTS

Learn the steps to install the Lighttpd web server along with the configuration of PHP CGI/FPM on Ubuntu 20.04 or 18.04 LTS server running on local machine or cloud hosting.

Lighttpd web server is one of the best available alternatives to popular Apache. It is light in weight and can easily be confirmed to delivers static or dynamic content via HTTP and HTTPS.  It is not only secure but also consumes fewer resources as compared to other web servers. We can use it with PHP with support to FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting, and many more. Also, it can be used with Python and other scripting languages ​​or converted into a proxy server via extensions. It is known for its lightweight and the ability to handle up to 10000 connections in parallel on a single server.

Here in this guide, we will take you through the steps of installing the Lighttpd web server on Ubuntu 20.04 or 18.04 LTS including the way to configure it with PHP and PHP-FPM.

Install Lighttpd web server with PHP-FPM on Ubuntu 20.04 LTs

What we need to follow this tutorial is the Ubuntu server,  a non-root user with sudo access and internet connection.

1. Update and Upgrade Server

Run system packages update and upgrade commands to makes sure all available packages on it are up to date. Also, this will force the system to rebuild repo cache which helps it to fetch the latest available packages for the installation purpose further in this tutorial.

sudo apt update
sudo apt upgrade

2. Install Lighttpd webserver

To install the Lighttpd server on Ubuntu 20.04 or 18.04 LTS Linux we don’t need any third-party repository, simply use the below command, and everything we need to use this web server will be on your Desktop or Server.

sudo apt-get install lighttpd

command to install web server lighttpd

3. Start, Enable & check the status of  Lighttpd Server

  • Once the installation is done, start the Lighttpd web server on your Linux server using the below command:
sudo systemctl start lighttpd
  • To make sure it automatically gets started with the system boot, enable it for that using the below command
sudo systemctl enable lighttpd
  • Finally, check the status to confirm everything is working absolutely fine
sudo systemctl status lighttpd
  • To check the version of the webserver you can use this command:
lighttpd -version
  • In case, you ever want to stop or restart it, then use these syntaxes:
sudo systemctl restart lighttpd
sudo systemctl stop lighttpd

Check lighttpd web server status


4. Test Lighttpd in a web browser

Before configuring PHP modules for Lighttpd, make sure the webserver is running and opening in the browse perfectly fine. Therefore, open the browser either on your local computer or if you are using the CLI server then on some other system.  For that type your system’s IP address where you have installed the webserver: http://ip-address

Lighttps web server installed on Ubuntu 20.04 Server

5. Install PHP

On Ubuntu 18.04 LTS, by default, the PHP version you will get to install is PHP 7.2 whereas on Ubuntu 20.04 LTS comes with the latest version that is PHP 7.4.3.

(Optional Step) If any of you want the latest version of PHP on Ubuntu 18.04 LTS then add the following PPA, otherwise, skip this step:

sudo add-apt-repository ppa:ondrej/php

sudo apt update

Here we will install PHP along with other extensions that we would need while setting up different CMS or web applications based on PHP. Thus, on your respective Ubuntu server, run the following command:

sudo apt-get install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip apache2-

In the above command, while installing the above packages of PHP, the Apache will automatically get installed, thus need to remove it. Therefore, to stop the system installing the apache2 as a dependency we used a dash at the end of its package name.


6. Enable FastCGI and FastCGI-PHP modules

Now, everything is done, just one more thing before we confirm that our PHP is absolutely working fine with Lighttpd is enabling the FastCGI extensions.

sudo lighty-enable-mod fastcgi fastcgi-php

Reload service to make the changes into effect

sudo service lighttpd force-reload

7. Testing Lighttpd with PHP info file

Let’s check whether the PHP is working fine with Lighttpd or note. For that, we will create a PHP Info file that will reveal all the information about installed PHP, web server, and enable modules or extensions.

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

Type or copy the below code to past in the created file:


Now, save it by pressing Ctrl+X, type Y, and hit the Enter key.

Now, in the browser type: http://server-ip-address/info.php

Note: Replace server-ip-address text with your server IP address.

The above will display the PHP info:

install PHP CGI and FPM for Lighttpd Check php installation with Lighttpd

If you run again the Lighttpd service status command you will get something like below this time:

h2s@ubuntu:/usr/bin$ systemctl status lighttpd
● lighttpd.service - Lighttpd Daemon
Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-09-19 00:06:16 PDT; 8min ago
Process: 43142 ExecStartPre=/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf (code=exited, status=0/>
Main PID: 43160 (lighttpd)
Tasks: 6 (limit: 4624)
Memory: 12.9M
CGroup: /system.slice/lighttpd.service
├─43160 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
├─43163 /usr/bin/php-cgi
├─43164 /usr/bin/php-cgi
├─43165 /usr/bin/php-cgi
├─43166 /usr/bin/php-cgi
└─43167 /usr/bin/php-cgi

Sep 19 00:06:16 ubuntu systemd[1]: Starting Lighttpd Daemon...
Sep 19 00:06:16 ubuntu systemd[1]: Started Lighttpd Daemon.
lines 1-17/17 (END)


So, in this way, we can install and configure Lighttpd with PHP CGI/FPM. If you want to go one step further to know how to install Content Management System WordPress on it then see our this tutorial.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.