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 AlmaLinux / CentOS 8
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.
A server with AlmaLinux as an operating system together with Lighttpd is a guarantee for an efficient and resource-efficient web server.
Install Lighttpd on AlmaLinux / CentOS 8
Installing Lighttpd is very easy to do but there are a few extra configurations to do.
Let’s start by adding the EPEL
repository to the system because that is where the lighttpd package is hosted.
sudo dnf install epel-release
Then, you can install the program by running the following command:
sudo dnf install lighttpd
This will install the package immediately.
By default, AlmaLinux does not start the service when a program is installed. Therefore we have to do it.
sudo systemctl start lighttpd
And now make the service start with the system.
sudo systemctl enable lighttpd
Then, you can test the operation of the service with the command
sudo systemctl status lighttpd
Output
● lighttpd.service - Lightning Fast Webserver With Light System Requirements Loaded: loaded (/usr/lib/systemd/system/lighttpd.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2021-04-14 16:54:29 CEST; 11s ago Main PID: 1247 (lighttpd) Tasks: 1 (limit: 12142) Memory: 1.1M CGroup: /system.slice/lighttpd.service └─1247 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf Apr 14 16:54:29 osradar systemd[1]: Started Lightning Fast Webserver With Light System Requirements. Apr 14 16:54:29 osradar lighttpd[1247]: 2021-04-14 16:54:29: (server.c.1404) can't have more connections than fds/2: 1024 1024
Also, you can check the installed version with the command:
lighttpd -v lighttpd/1.4.55 (ssl) - a light and fast webserver
Install PHP on AlmaLinux / CentOS 8
One way to test the performance of the webserver, you have to install PHP and make it work with Lighttpd
sudo dnf install php php-mysqlnd php-pdo php-gd php-mbstring php-fpm php-fpm lighttpd-fastcgi
Now we need to make it work with Lighttpd by editing some configuration files.
sudo nano /etc/php-fpm.d/www.conf
And modify the group
and user
values to be lighttpd
values.
user = lighttpd group = lighttpd
In this same file, modify the value of listen
to this one
listen = 127.0.0.1:9000
Save the changes and close the file.
Now edit the /etc/php.ini
file, which also needs to be modified by one value
sudo nano /etc/php.ini
And edit the cgi.fix_pathinfo
value to 1
.
cgi.fix_pathinfo=1
Now, make another change to the /etc/lighttpd/modules.conf
file and uncomment the following line:
include "conf.d/fastcgi.conf"
Save the changes and close the editor.
Finally, we have to edit another configuration file called fastcgi.conf
where we have to add the server that will listen for PHP requests.
sudo nano /etc/lighttpd/conf.d/fastcgi.conf
And add this to the end of the file
fastcgi.server += ( ".php" => (( "host" => "127.0.0.1", "port" => "9000", "broken-scriptfilename" => "enable" )) )
Again, save the changes and close the editor.
Then, restart the lighttpd
service and start and enable php-fpm
.
sudo systemctl restart lighttpd sudo systemctl start php-fpm.service sudo systemctl enable php-fpm.service
Test Lighttpd and PHP on AlmaLinux / CentOS 8
The best way to know if everything is OK is to create a PHP file and check if it is interpreted.
So, create a PHP file with any valid code such as the phpinfo
method in the default root directory.
sudo nano /var/www/lighttpd/info.php
<?php
phpinfo();
?>
Save the changes and access it from a web browser, for example http://your-domain/info.php
or http://ip-server/info.php
.
This checks that everything is working properly.
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.