Hello, friends. In this short and simple post, you will learn how to install Lighttpd on Ubuntu 22.04. You will also learn how to add PHP support.
For those who don’t know, lighttpd is a secure, fast, compliant, and very flexible web server that has been optimized for high-performance environments.
One of the main things that make it so popular is that it is quite lightweight and can revive web servers.
Let’s go for it.
Install Lighttpd on Ubuntu
One of the most important advantages of Lighttpd is that it is present in the official Ubuntu 22.04 repositories, so it’s all easy.
First, connect via SSH to the server.
Then, update the whole system
sudo apt update
sudo apt upgrade
Thereafter, you can install Lighttpd from the official repositories with this command
sudo apt install lighttpd
As soon as you install it, you can check the installed version
lighttpd -version
Sample Output:
lighttpd/1.4.63 (ssl) - a light and fast webserver
Similar to Apache or Nginx, Lighttpd works as a system service. So, before using it, initialize it and have it run at system startup
sudo systemctl enable --now lighttpd
Then, you can check the status of the service
sudo systemctl status lighttpd
Sample output
● lighttpd.service - Lighttpd Daemon
Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-11-10 23:01:08 UTC; 15min ago
Main PID: 1495 (lighttpd)
Tasks: 1 (limit: 4538)
Memory: 948.0K
CPU: 410ms
CGroup: /system.slice/lighttpd.service
└─1495 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
Nov 10 23:01:08 unixcop systemd[1]: Starting Lighttpd Daemon...
Nov 10 23:01:08 unixcop systemd[1]: Started Lighttpd Daemon.
Open the firewall ports
sudo ufw allow 80
sudo ufw allow 443
sudo ufw reload
Finally, open a browser and check http://your-server
.
This indicates that it works fine.
Adding PHP support to Lighttpd
The normal thing to do is to add PHP support. First, install it
sudo apt install php php-cgi php-cli php-fpm
Now we have to add support in the Lighttpd configuration file.
Open it with any text editor
sudo vim /etc/php/*/fpm/pool.d/www.conf
And replace:
listen = /run/php/php/*-fpm.sock
For:
listen = 127.0.0.1:9000
Save the changes and close the editor.
The next step is to enable fastcgi
which will be used for PHP processing. Edit the respective configuration file:
sudo vim /etc/lighttpd/conf-available/15-fastcgi-php.conf
Replace
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",
For these:
"host" => "127.0.0.1",
"port" => "9000",
Save the changes and close the editor.
Now, enable the FastCGI module
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
An restart lighttpd
sudo systemctl restart lighttpd
Testing the changes
The best way to test the changes is to create a PHP file.
sudo vim /var/www/html/test.php
And add some content
<?php
phpinfo();
?>
And I’m done.
Now open it with your favorite web browser.
Conclusion
Lighttpd is a great choice for a lightweight web server with many features.