Lighttpd Setup on Ubuntu 22.04: Best Web Server
This guide provides a comprehensive walkthrough for Lighttpd Setup on Ubuntu 22.04. Lighttpd, often pronounced "Lighty," is a lightweight, high-performance web server renowned for its speed, security features, and adaptability. It stands out as an ideal choice for resource-constrained environments, dynamic websites, and a wide array of applications.
Lighttpd boasts cross-platform compatibility, operating seamlessly on both Windows and Linux operating systems. Let’s dive into the detailed steps to successfully complete Lighttpd Setup on Ubuntu 22.04.
Steps To Install and Configure Lighttpd on Ubuntu 22.04
Before embarking on the Lighttpd installation process, ensure you are logged into your Ubuntu 22.04 server as a non-root user with sudo privileges. Furthermore, it is highly recommended to set up a basic firewall for enhanced security. If you haven’t already done so, refer to our comprehensive guide on Initial Server Setup with Ubuntu 22.04.
Once your server is properly prepared, proceed with the following steps to complete Lighttpd Setup on Ubuntu 22.04:
1. Lighttpd Setup on Ubuntu 22.04
Lighttpd packages are readily available in the default Ubuntu repository. Start by updating your local package index to ensure you have the latest package information:
sudo apt update -y
Next, install Lighttpd using the following command:
sudo apt install lighttpd -y
Manage Lighttpd Web Server
After the installation, start and enable the Lighttpd service to ensure it automatically starts upon system boot:
# sudo systemctl start lighttpd
# sudo systemctl enable lighttpd
Verify that Lighttpd is active and running on your Ubuntu 22.04 server by executing:
sudo systemctl status lighttpd
The output should resemble the following:

To ascertain the specific version of Lighttpd installed on your server, use the following command:
lighttpd -v
**Output**
lighttpd/1.4.63 (ssl) - a light and fast webserver
2. Install MariaDB support for Lighttpd on Ubuntu 22.04
To provide database support, install the necessary dependencies and packages using:
sudo apt install curl software-properties-common dirmngr ca-certificates apt-transport-https -y
Import the MariaDB repository using the official MariaDB bash script designed for supported Linux distributions, including Ubuntu LTS releases:
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.11
Update your local package index again:
sudo apt update
Now, install MariaDB server and client:
sudo apt install mariadb-server mariadb-client -y
Verify the MariaDB installation by checking its version:
mariadb --version
**Output**
mariadb Ver 15.1 Distrib 10.11.2-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
Manage MariaDB Service
Start and enable the MariaDB service to ensure it starts on boot:
# sudo systemctl start mariadb
# sudo systemctl enable mariadb
Confirm that MariaDB is active and running:
sudo systemctl status mariadb

MySQL Security Script
Secure your MariaDB installation by running the security script:
sudo mysql_secure_installation

Access the MariaDB shell using the following command:
sudo mysql -u root -p

3. Install PHP and PHP-FPM with FastCGI
Enable PHP-FPM with FastCGI support by installing PHP and the necessary extensions:
sudo apt install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip -y
Confirm your PHP installation by checking its version:
php --version

Enable PHP-FPM Module
To enable the PHP-FPM module, edit the www.conf
file:
sudo vi /etc/php/*/fpm/pool.d/www.conf
Find the line:
listen = /run/php/php*-fpm.sock
And change it to:
listen = 127.0.0.1:9000
Save and close the file.
To list all loaded PHP Modules, run the following command :
php -m
Enable FastCGI Module
To enable the FastCGI module, open the following file:
sudo vi /etc/lighttpd/conf-available/15-fastcgi-php.conf
Find the following lines under the FastCGI.server:
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/run/lighttpd/php.socket",
Replace the lines with the following:
"host" => "127.0.0.1",
"port" => "9000",
Save and close the file.
4. Test Lighttpd Web Server
Test your installation by creating a simple PHP info file:
sudo vi /var/www/html/phpinfo.php
Add the following content to the file:
<?php
phpinfo();
?>
Save and close the file.
Set the correct permission and ownership:
# sudo chown -R www-data:www-data /var/www/html/
# sudo chmod -R 755 /var/www/html/
Edit the Lighttpd config file and add the module mod_fastcgi to your server configuration:
sudo vi /etc/lighttpd/lighttpd.conf
Add mod_fastcgi
to the server.modules section:
server.modules = (
"mod_indexfile",
"mod_access",
"mod_alias",
"mod_redirect",
"mod_fastcgi",
)
Next, add the following contents just below the file above to configure fastcgi.server.
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
)))
Finally, restart Lighttpd to apply the changes:
sudo systemctl restart lighttpd
Access your PHP Info page by typing your server’s IP address in your web browser followed by /phpinfo.php
:
http://your-server-ip/phpinfo.php
You will see the following screen:

From there, you will see working information on PHP, PHP-FPM, and MySQL with lots of other modules that are already enabled.
For more information, you can visit the Lighttpd Documentation page.
Conclusion
At this point, you have successfully learned how to Install and Configure Lighttpd Web Server on Ubuntu 22.04.
Alternative Solutions for Serving Dynamic Content with Lighttpd
While the above guide details a standard approach using PHP-FPM and FastCGI, here are two alternative methods for serving dynamic content with Lighttpd:
1. Using uWSGI:
uWSGI is a versatile application server protocol that can be used to serve Python, Ruby, and other dynamic content languages. It’s known for its performance and support for various deployment scenarios.
-
Explanation: Instead of PHP-FPM, you would configure uWSGI to handle your dynamic application requests. Lighttpd would then forward requests to the uWSGI server using the uwsgi protocol. This method is particularly well-suited for Python-based web applications.
-
Code Example (Conceptual – Configuration snippets):
First, install uWSGI:
sudo apt install uwsgi uwsgi-plugin-python3
Then, create a configuration file for your Python application (e.g.,
my_app.ini
):[uwsgi] module = my_app callable = app master = true processes = 4 socket = /tmp/my_app.sock chmod-socket = 660 vacuum = true
Configure Lighttpd to forward requests to the uWSGI socket (add to
/etc/lighttpd/lighttpd.conf
):server.modules += ( "mod_proxy" ) proxy.server = ( "/" => ( ( "socket" => "/tmp/my_app.sock", "check-local" => "disable" ) ) )
Note: This is a simplified example. Configuration details will depend on the specific application framework (e.g., Flask, Django) and deployment requirements.
2. Using a Reverse Proxy to Another Web Server:
Another approach involves using Lighttpd as a reverse proxy to another web server, such as Apache or Nginx, that is configured to handle the dynamic content.
-
Explanation: Lighttpd would act as the front-end server, handling static content and forwarding requests for dynamic content to a backend web server. This allows you to leverage the strengths of both servers – Lighttpd’s speed for static files and the other server’s capabilities for dynamic content processing.
-
Code Example (Conceptual – Configuration snippets):
Assume you have Nginx running on the same server on port 8080. Configure Lighttpd to proxy requests to Nginx (add to
/etc/lighttpd/lighttpd.conf
):server.modules += ( "mod_proxy" ) proxy.server = ( "/" => ( ( "host" => "127.0.0.1", "port" => 8080, "check-local" => "disable" ) ) )
Now, any requests that Lighttpd receives will be forwarded to Nginx on port 8080. You would then configure Nginx to handle the PHP processing (or any other dynamic content).
These alternative solutions offer different trade-offs in terms of performance, complexity, and resource usage. The choice depends on the specific requirements of your web application and your familiarity with the different technologies involved. The original article provides a solid foundation for Lighttpd Setup on Ubuntu 22.04, and these alternatives expand your options for serving dynamic content.