In this article, we will have explained the necessary steps to install and configure Lighttpd on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Lighttpd is a “secure, fast, compatible, and very flexible” web server optimized for high-performance environments. It consumes very few resources compared to other web servers and especially fast for running AJAX applications. Lighttpd comes with a rich set of features, such as FastCGI, SCGI, Auth, URL-Rewriting, Output-Compression, event mechanism, and more.
Install Lighttpd on Ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install Lighttpd on Ubuntu.
Run following command to install Lighttpd web server:
sudo apt install lighttpd
Once successfully install Lighttpd, start and enable the service to automatically start at boot time:
sudo systemctl start lighttpd sudo systemctl enable lighttpd sudo systemctl status lighttpd
Then, open a web browser and go to http://localhost
if you installed locally or http://your-server-ip
if you installed remotely.
Step 3. Adding PHP support to Lighttpd on Ubuntu.
The first step is to install PHP and some of its modules, to do this, use the following command:
sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cli php7.4-curl php7.4-xml
By default, PHP-FPM listens on the UNIX socket /var/run/php74-fpm.sock.
So, we will need to modify the file /etc/php/7.4/fpm/pool.d/www.conf
and set PHP-FPM to listens on TCP socket:
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
listen = 127.0.0.1:9000
Then you have to make other changes in another configuration file. So, open the file /etc/lighttpd/conf-available/15-fastcgi-php.conf:
sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
"bin-path" => "/usr/bin/php-cgi", "socket" => "/var/run/lighttpd/php.socket",
To
"host" => "127.0.0.1", "port" => "9000",
Save and close the file. Then, enable FastCGI and FastCGI-PHP modules with the following command:
sudo lighty-enable-mod fastcgi sudo lighty-enable-mod fastcgi-php
Finally, restart Lighttpd and PHP-FPM service to apply all the configuration changes:
sudo systemctl restart lighttpd sudo systemctl restart php7.4-fpm
Step 4. Configure Firewall
Issue the following commands to allow HTTP (80) and HTPPS (443) request through the firewall:
ufw allow 80/tcp ufw allow 443/tcp ufw reload
That’s all you need to do to install Lighttpd on Ubuntu 20.04 Focal Fossa. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.