You need to learn how to install lighttpd server on Ubuntu 22.04 to set up a zippy and light web server, so keep reading to find out more.
A lightweight web server optimized for speed-critical environments, lighttpd comes with many applications. For this article, we’ll start with a brief discussion of lighttpd and its features, followed by a guide on installing it. Lastly, we will also see how we can configure the webserver to run PHP pages.
What is a lighttpd server?
Lighttpd is another web server similar to Apache. Its advantage over Apache is that it is lightweight and requires fewer resources than Apache. The following are the main features of the lighttpd server:
- It is developed by Jan Kneschke and is extensible via a large number of modules
- It is suitable for situations where a more significant workload is required. It is also helpful for systems with minimal capacity or weak configuration
- It can run various server-side scripting languages with the help of CGI. For instance, you can run PHP code with the help of FastCGI. For python and Ruby, you can use SCGI.
How to Install Lighttpd Server on Ubuntu 22.04
The installation of lighttpd on Ubuntu is straightforward. Unlike Apache, it doesn’t require the installation of any third-party software. To install the server, perform the following steps.
Open the Terminal
Go to the System Menu and select the Terminal to open it.
Update the system
In the next step, we will update and upgrade the system. Type the following commands on your Terminal:
$sudo apt update
$sudo apt upgrade
Install lighttpd server
Then, type the following command on the Terminal for the installation of lighttpd:
$sudo apt install lighttpd –y
Verifying the installation of the lighttpd server
After the installation of the lighttpd server, you can verify the installation by checking its version with the help of the following command:
You should see the following output:
lighttpd/1.4.63 (ssl) - a light and fast webserver
Starting and enabling the lighttpd service
Once the installation is completed, we need to start and enable the lighttpd service. In this way, it will work as a system service. Perform the steps below.
Start lighttpd service
Start the lighttpd service by running the following command:
$sudo systemctl start lighttpd
Enable lighttpd service
In addition to starting, enable the lighttpd service via the following command:
$sudo systemctl enable lighttpd
Check the status of lighttpd
Now, check the status of lighttpd with the help of the following command:
$systemctl status lighttpd
Open the firewall ports
Also, you should open the firewall ports. Allow the ports 80 and 443 via running the following commands:
$sudo ufw allow 80
$sudo ufw allow 443
Reload the firewall
Now, reload the firewall using the following commands:
$sudo ufw reload
Browse the lighttpd server
Now, open your preferred browser and point your browser to the following address:
You should see the following page:
Configure PHP on lighttpd
After learning how to install httpd, we will see how PHP pages can be served with the server. We will first configure the PHP via the following steps.
The first step is to install the PHP with appropriate extensions. Run the following command to install it:
$sudo apt install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip
You can verify that php is installed correctly by running the following command:
In the next step, we will configure PHP-FM. First, open the configuration file by running the following command:
$sudo nano /etc/php/*/fpm/pool.d/www.conf
Look for the attribute “listen” and change it as follows:
listen = 127.0.0.1:9000
As the next step, we will enable FastCGI. For this purpose, first, open the configuration file via the following command:
$sudo nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
Change the lines starting with “bin-path” and “socket” as follows:
"host" => "127.0.0.1",
"port" => "9000",
Now, enable FastCGI via the following commands:
$sudo lighty-enable-mod fastcgi
$sudo lighty-enable-mod fastcgi-php
Test if PHP is working with lighttpd
Having configured the PHP, we will now test if the PHP is working fine with lighttpd. Follow the steps below.
Create the PHP file
First, create a test PHP file with the command:
$sudo nano /var/www/html/phpinfo.php
Edit the PHP file
The file “phpinfo.php” is opened. We can edit it and paste some code. Paste the following sample PHP code into the file:
Make lighttpd the owner of the PHP directory
Make the lighttpd owner of the PHP directory with the help of the following command:
$sudo chown -R www-data:www-data /var/www/html/
$sudo chmod -R 755 /var/www/html/
Restart lighttpd server
Finally, restart the lighttpd server to apply the changes. Type the following command on your Terminal:
$sudo /etc/init.d/lighttpd restart
Browse the PHP file
Now, we will browse the PHP file to see if the PHP integration with lighttpd is working correctly. For this purpose, open your favorite browser and point to the following address:
Alternatively, you can also try the following address:
You should see the following page:
If the page appears above, you have successfully installed lighttpd and integrated it with PHP.
In this article, we briefly discussed the lighttpd server installation. It is a lightweight web server similar to Apache. We went over its installation and integration with PHP. The basic steps for the installation and configuration are provided.
Besides, PHP other software, such as WordPress, can also be integrated with the lighttpd server.
If this guide helped you, please share it.