Lighttpd, a fast and very flexible server for Ubuntu 20.04

about lighttpd

In the next article we will take a look at how can we install Lighttpd server on Ubuntu 20.04. This is a secure, fast, and flexible web server that is optimized for high-performance environments. It consumes very little resources compared to other web servers, and it is especially fast for running AJAX applications. It is also open source, and uses a BSD license. Works on UNIX-like systems.

Combining Ubuntu 20.04 with Lighttpd is an interesting bet if you are interested in a fast, efficient and secure web server. This server leaves a small memory footprint if you compare it to other web servers, it also has an efficient management of the CPU load and a set of advanced functions (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more).

Install Lighttpd on Ubuntu 20.04

Lighttpd is a very popular alternative to the popular web servers on Unix family operating systems. Thanks to this, We can find it available through the main Ubuntu 20.04 repositories. Therefore, to install it in Ubuntu 20.04, we will only have to open a terminal (Ctrl + Alt + T) and execute the command:

install lighttpd

sudo apt install lighttpd

Lighttpd is managed as a system service, and therefore we will be able to start it by typing in the terminal:

sudo systemctl start lighttpd

And we can stop it with this other command:

sudo systemctl stop lighttpd

It will also give us the possibility of know the status of the service typing in terminal:

status lighttpd

sudo systemctl status lighttpd

When the server is up and running, we can open a web browser and go to http: // localhost if we install it locally, or http: // server-ip if we install it remotely.

localhost lighttpd

Add PHP support to Lighttpd

It has to be said that we will need to install PHP so that dynamic websites can be interpreted, since by default it does not. With this we guarantee that a good part of the applications created with this language can be used on our server. We will can install PHP with the following command:

install php for lighttpd

sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cli php7.4-curl php7.4-xml

When the PHP installation is done, a few small changes need to be made so that Lighttpd can work with PHP and interpret the websites. The first thing will be open one of the configuration files with our favorite editor:

sudo vim /etc/php/7.4/fpm/pool.d/www.conf

AND inside the file change the value of ‘listen’ to:

listen value

listen = 127.0.0.1:9000

Then we save the changes and close the file. The next step will be make more changes to another configuration file. So, let’s open it:

sudo vim /etc/lighttpd/conf-available/15-fastcgi-php.conf

And inside we are going to change the following lines:

"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",

For these others:

configuration-15-fastcgi-php

"host" => "127.0.0.1",
"port" => "9000",

When finished, we save the changes and close the file.

At this point, it only remains to run the following commands to enable modules that will make Lighttpd work with PHP:

enable lighttpd modules with php

sudo lighty-enable-mod fastcgi

sudo lighty-enable-mod fastcgi-php

Finished restarting the Lighttpd and php-fpm services:

sudo systemctl restart lighttpd php7.4-fpm

Checking that PHP is enabled

To test if everything we’ve done works, we are going to write a PHP file in the root directory of Lighttpd, and then open it with the browser.

We are going to create this file with the command:

sudo vim /var/www/html/test.php

Inside the file, we are going to paste the following text. Then we save and close the file.

<?php phpinfo();?>

Returned at the terminal, we will have to change the permissions of the directory and make Lighttpd the owner of it. We will do this by executing the commands:

directory permissions

sudo chown -R www-data:www-data /var/www/html/

sudo chown -R 755 /var/www/html/

Now if we open the browser and we go to the newly created file with the URL http: //your-server/test.php we should see something like the following:

php lighttpd version

You may need to restart the Lighttpd server for the file to load correctly test.php we just created.

As indicated in OSRadar, Lighttpd stands out for being very light in the execution of web applications. For this reason, it can serve us for many interesting things in our daily work on a server. For more information about this server we can consult the documentation offered in the project website. In addition we can also obtain more information in your GitHub repository.

Add Comment