25 C
Texas
angeloma
Senior Writer and partner

How to install Lighttpd on Ubuntu 20.04?

There are many web services in Unix but we always look for the one that best suits our needs. In this case, we will show you how to install Lighttpd on Ubuntu 20.04.

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. It is also open source and uses a BSD license and works on UNIX-like systems, such as Linux or BSD.

Combining Ubuntu 20.04 with Lighttpd is a safe bet if you want a fast, efficient and secure web server. Go for it.

Install Lighttpd on Ubuntu 20.04

As Lighttpd is a very popular alternative to web servers on Unix family operating systems, it is available through the Ubuntu 20.04 main repositories

- Advertisement -

Therefore, to install Lighttpd on Ubuntu 20.04, just open a new terminal and run it:

:~$ sudo apt install lighttpd
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
gamin libgamin0 spawn-fcgi
Suggested packages:
rrdtool php-cgi apache2-utils lighttpd-doc lighttpd-mod-authn-gssapi lighttpd-mod-authn-pam lighttpd-mod-authn-sasl lighttpd-mod-cml lighttpd-mod-geoip
lighttpd-mod-magnet lighttpd-mod-maxminddb lighttpd-mod-trigger-b4-dl lighttpd-mod-vhostdb-dbi lighttpd-mod-vhostdb-pgsql lighttpd-mod-webdav lighttpd-modules-ldap
lighttpd-modules-mysql
The following NEW packages will be installed:
gamin libgamin0 lighttpd spawn-fcgi
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 398 kB of archives.
After this operation, 1538 kB of additional disk space will be used.
Do you want to continue? [Y/n]
1.- Installing Lighttpd on Ubuntu 20.04
1.- Installing Lighttpd on Ubuntu 20.04

This way it will be installed and ready to use on our server.

On the other hand, Lighttpd is managed as a system service and therefore you can start it with this command:

:~$ sudo systemctl start lighttpd

Or stop it:

:~$ sudo systemctl stop lighttpd

Or know the status of the service:

:~$ sudo systemctl status lighttpd

Then open a web browser and go to http://localhost if you installed locally or http://server-ip if you installed remotely.

If everything went well, you will see the following screen.

2.- Lighttpd default page
2.- Lighttpd default page

However, PHP has to be installed so that dynamic websites can be interpreted.

Adding PHP support to Lighttpd on Ubuntu 20.04

The next step is to install PHP which is one of the most popular web programming languages available. With this we guarantee that a good part of the applications created with this language can be used in our server.

So, you can install PHP with the following command:

:~$ sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cli php7.4-curl php7.4-xml
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
php-common php7.4-common php7.4-json php7.4-opcache php7.4-readline
Suggested packages:
php-pear
The following NEW packages will be installed:
php-common php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-json php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml
0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
Need to get 4334 kB of archives.
After this operation, 19.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
3.- Installing PHP on Ubuntu 20.04
3.- Installing PHP on Ubuntu 20.04

Now some changes have to be made so that Lighttpd can work with PHP and interpret the websites.

First, open the Lighttpd configuration file which is /etc/php/7.4/fpm/pool.d/www.conf

:~$ sudo nano /etc/php/7.4/fpm/pool.d/www.conf

And change the list value to this:

listen = 127.0.0.1:9000

If you want you can simply comment on the line and add this one.

Save the changes and close the file.

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

And change the following lines:

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

To:

"host" => "127.0.0.1",
"port" => "9000",
4.- Configuring Lighttpd on Ubuntu 20.04
4.- Configuring Lighttpd on Ubuntu 20.04

Then save the changes and close the file.

Then execute the following commands to enable the modules that will make Lighttpd work with PHP.

:~$ sudo lighty-enable-mod fastcgi
Enabling fastcgi: ok
Run "service lighttpd force-reload" to enable changes

:~$ sudo lighty-enable-mod fastcgi-php
Enabling fastcgi-php: ok
Run "service lighttpd force-reload" to enable changes

Finally restart Lighttpd and php-fpm services

:~$ sudo systemctl restart lighttpd php7.4-fpm

To test if everything we have done works, just write a PHP file in the Lighttpd root directory and open it with the browser.

So, create the file and add the following content:

:~$ sudo nano /var/www/html/test.php
<?php
phpinfo();
?>

Again, save the changes and close the file.

Also, you should change the permissions of the directory and make Lighttpd the owner of it:

:~$ sudo chown -R www-data:www-data /var/www/html/
:~$ sudo chown -R 755 /var/www/html/

And now yes, open your browser and open the file http://your-server/test.php and you will see the following:

5.- PHP working with Lighttpd
5.- PHP working with Lighttpd

So, that is it. Enjoy Lighttpd.

Conclusion

Lighttpd stands out for being very light in the execution of web applications. So it can serve us for many interesting things in our daily work on a server. Today we have learned to install it on a server with Ubuntu 20.04 and we have also added support for PHP.

Please share this post and join our Telegram channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article