Install Lighttpd on AlmaLinux 9: Best Web Server

In this guide, you will learn to Install Lighttpd on AlmaLinux 9. Lighttpd, a high-performance open-source Web server (licensed under the revised BSD license) was developed by Jan Kneschke.

Lighttpd is an IPv4 and IPv6 compatible Web server that understands HTTP/1.0 and 1.1, HTTPS (using OpenSSL) CGI/1.1, native FastCGI, and HTTP authentication. It allows for virtual hosts, directory listings, streaming CGI and FastCGI, URL-Rewriting, HTTP-Redirects, output-compression with transparent caching, automatic expiration of files, and has Large File support.

Lighttpd is very PHP-focused. It provides the same speed or better than Apache + mod_php4 and handles various PHP bugs in the FastCGI SAPI. You can now proceed to the following steps below on the Orcacore website to finish the Lighttpd setup on AlmaLinux 9.

Steps To Install Lighttpd Web Server on AlmaLinux 9

To install Lighttpd, you need to log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our article on the Initial Server Setup with AlmaLinux 9.

1. Install Lighttpd on AlmaLinux 9

One way to install Lighttpd is by adding the Epel release repository. First, update your local package index with the command below:

sudo dnf update -y

Then, install the Epel release on AlmaLinux 9 with the following command:

sudo dnf install epel-release -y

Now you can use the following command to install Lighttpd:

sudo dnf install lighttpd -y

Start and Enable Lighttpd Service

Start and enable your Lighttpd service to start on boot with the commands below:

# sudo systemctl start lighttpd
# sudo systemctl enable lighttpd

Verify that your Lighttpd service is active and running on AlmaLinux 9 with the following command:

sudo systemctl status lighttpd

In your output you will see:

Lighttpd service status

Also, you can use the following command to check your Lighttpd version on AlmaLinux 9:

lighttpd -v

You will get the following output:

Output
lighttpd/1.4.67 (ssl) - a light and fast webserver

Configure Firewall For Lighttpd

Here we assumed that you have enabled firewalld from the requirements. Now you need to allow traffic on HTTP and HTTPS through your AlmaLinux firewall:

# sudo firewall-cmd --permanent --zone=public --add-service=http
# sudo firewall-cmd --permanent --zone=public --add-service=https

Then, reload the firewall to apply the new rules:

sudo firewall-cmd --reload

Now you can access your Lighttpd defaults page on AlmaLinux 9 by typing your server’s IP address in your web browser:

http://Your-IP-addr

2. Install MariaDB For Lighttpd Web Server

At this point, we use MariaDB as the database engine. To install it, run the command below:

sudo dnf install mariadb mariadb-server -y

Once your installation is completed, start and enable your MariaDB service with the commands below:

# sudo systemctl start mariadb.service
# sudo systemctl enable mariadb.service

Check your MariaDB is active and running:

sudo systemctl status mariadb.service

In your output, you should see:

MariaDB service status for Lighttpd

Then, you need to secure your MariaDB installation with the command below:

sudo mysql_secure_installation

This will ask you to create a new root password, remove anonymous users, disable root login remotely, remove the test database, and reload the privilege table.

3. Install and Configure PHP For Lighttpd Web Server

At this point, you can easily install PHP and PHP-FPM for Lighttpd. To do this, run the following command:

sudo dnf install php php-mysqlnd php-pdo php-gd php-mbstring php-fpm lighttpd-fastcgi -y

Then, you need to open the php-fpm configuration file with your desired text editor like Vi Editor or Nano Editor:

sudo vi /etc/php-fpm.d/www.conf

In the file, find the user and group line and change their value to Lighttpd:

Change user and group to Lighttpd

Also, php-fpm uses listen = /run/php-fpm/www.sock socket, you need to make this line to listen = 127.0.0.1:9000 as TCP connection.

Change listen = /run/php-fpm/www.sock value

When you are done, save and close the file. Then, start and enable your PHP-FPM service:

# sudo systemctl start php-fpm.service
# sudo systemctl enable php-fpm.service

Check your PHP-FPM service is active and running:

sudo systemctl status php-fpm.service
Check PHP-FPM service status

4. Enable FastCGI support in PHP and Lighttpd Web Server

In this step, you need to enable the PHP and PHP-FPM with FastCGI for the Lighttpd web server. First, open the /etc/php.ini file:

sudo vi /etc/php.ini

Find the below line and uncomment it by removing the “;”.

cgi.fix_pathinfo=1

Save and close the file once you are done.

Then, open the /etc/lighttpd/modules.conf:

sudo vi /etc/lighttpd/modules.conf

In the file, look for the following line and uncomment it:

include conf_dir + "conf.d/fastcgi.conf"

Save and close the file. Finally, open the /etc/lighttpd/conf.d/fastcgi.conf file:

sudo vi /etc/lighttpd/conf.d/fastcgi.conf

Go to the end of the file and the following lines:

fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

Once you are finished, save and close the file.

Restart Lighttpd service on AlmaLinux 9 to apply the changes:

sudo systemctl restart lighttpd

To test the configuration, you can a phpinfo.php file under /var/www/lighttpd/ directory:

sudo vi /var/www/lighttpd/phpinfo.php

Add the following lines to the file:

<?php
phpinfo();
?>

Save and close the file.

Now you can navigate to the following URL to test the FastCGI support in PHP:

http://Your-IP-addr/phpinfo.php

Conclusion

Lighttpd is a web server that is great for handling websites that need to be fast and efficient, especially when there’s a lot of traffic. At this point, you have learned to Install Lighttpd on AlmaLinux 9.

Hope you enjoy it. You may also like these articles:

Steps To Install PHP 7.4 on AlmaLinux 9

Install and Configure WordPress on Rocky Linux 9

Install OpenSSL on AlmaLinux 9

RPM Package Management in AlmaLinux

Install VLC Media Player in AlmaLinux 9

Install Scala 3 in AlmaLinux 9

Install Froxlor Control Panel on RHEL 8

LibreOffice 24.2.4 Office Suite Is Available for Downloading

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!