How To Install Lighttpd on Rocky Linux 9
In this tutorial, we will show you how to install Lighttpd on Rocky Linux 9. For those of you who didn’t know, Lighttpd is an open-source web server that focused on simplicity and high performance. It supports several technologies, including PHP, FastCGI, Auth, SSL, URL rewriting, reverse proxy, load balancing, and much more. It has a small memory footprint usage than other popular web servers like Apache and Nginx and is capable of handling many concurrent connections.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Lighttpd web server on Rocky Linux. 9.
Prerequisites
- A server running one of the following operating systems: Rocky Linux 9.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Lighttpd on Rocky Linux 9
Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:
sudo dnf check-update sudo dnf install dnf-utils sudo dnf install epel-release
Step 2. Installing Lighttpd on Rocky Linux 9.
By default, Lighttpd is available on the Rocky Linux 9 base repository. Now we install the latest version of Lighttpd using dnf
the command:
sudo dnf install lighttpd
You can start the Lighttpd service and configure it to run on startup by entering the following commands:
sudo systemctl start lighttpd sudo systemctl enable lighttpd sudo systemctl status lighttpd
You can also verify the Lighttpd version with the following command:
lighttpd -v
To make your pages available to the public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
Step 3. Installing MariaDB.
By default, MariaDB is available on the Rocky Linux 9 base repository. Simply install the MariaDB package by using the dnf
command:
sudo dnf install mariadb-server mariadb
After the installation is completed, start the service of the Database server and then enable the same, so that it could start itself automatically with the system reboot:
sudo systemctl restart mariadb sudo systemctl status mariadb sudo systemctl enable mariadb
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
mysql_secure_installation
For additional resources on installing MariaDB Database, read the post below:
Step 4. Installing PHP and PHP-FPM with FastCGI.
PHP is a popular scripting language that powers the dynamic content of millions of websites and apps. Now we run the commands below to install PHP:
sudo dnf install php php-mysqlnd php-pdo php-gd php-mbstring php-fpm lighttpd-fastcgi
Next, edit the PHP-FPM configuration file and change the user and group to Lighttpd:
nano /etc/php-fpm.d/www.conf
Change the following lines:
user = lighttpd group = lighttpd
After that, find the following line:
;listen = /run/php-fpm/www.sock listen = 127.0.0.1:9000
Save and close the file, then start the PHP-FPM service and enable it to start at system reboot:
sudo systemctl enable php-fpm sudo systemctl start php-fpm
Step 5. Configure PHP and PHP-FPM Support in Lighttpd.
Now edit the /etc/php.ini
file, which also needs to be modified by one value:
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"
Finally, we have to edit another configuration file called fastcgi.conf
where we have to add the server that will listen to PHP requests:
nano /etc/lighttpd/conf.d/fastcgi.conf
Add the following lines at the end of the file:
fastcgi.server += ( ".php" => (( "host" => "127.0.0.1", "port" => "9000", "broken-scriptfilename" => "enable" )) )
Save and close the file, then restart the PHP-FPM and Lighttpd service to apply the changes:
sudo systemctl restart lighttpd sudo systemctl restart php-fpm
Congratulations! You have successfully installed Lighttpd. Thanks for using this tutorial for installing the Lighttpd web server on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Lighttpd website.