Install Lighttpd on AlmaLinux 9: Best Web Server – OrcaCore
In this comprehensive guide, you’ll discover how to Install Lighttpd on AlmaLinux 9. Lighttpd, a lightweight and high-performance open-source web server, is released under the revised BSD license and was created by Jan Kneschke.
Lighttpd boasts compatibility with both IPv4 and IPv6 networks, understanding HTTP/1.0 and 1.1 protocols, HTTPS (secured by OpenSSL), CGI/1.1, native FastCGI, and HTTP authentication. Key features include virtual host support, directory listings, streaming CGI and FastCGI capabilities, URL rewriting, HTTP redirects, output compression with transparent caching, automatic file expiration, and large file support.
Lighttpd is particularly well-suited for PHP-based applications. It can match or even surpass the performance of Apache with mod_php4, while effectively handling common PHP bugs in the FastCGI SAPI. Follow the steps outlined below, provided by Orcacore, to complete your Lighttpd setup on AlmaLinux 9.
Before you begin, ensure you’re logged into your server as a non-root user with sudo privileges and have configured a basic firewall. Refer to our guide on Initial Server Setup with AlmaLinux 9 for detailed instructions.
1. Install Lighttpd on AlmaLinux 9
One straightforward method to install Lighttpd is by utilizing the EPEL (Extra Packages for Enterprise Linux) repository. Begin by updating your local package index:
sudo dnf update -y
Next, install the EPEL release repository on your AlmaLinux 9 system:
sudo dnf install epel-release -y
Finally, install Lighttpd using the following command:
sudo dnf install lighttpd -y
Start and Enable Lighttpd Service
Start the Lighttpd service and enable it to launch automatically at boot time:
# sudo systemctl start lighttpd
# sudo systemctl enable lighttpd
Confirm that the Lighttpd service is active and running on your AlmaLinux 9 server:
sudo systemctl status lighttpd
The output should resemble the following:

To verify the installed Lighttpd version, use the command:
lighttpd -v
This will produce output similar to:
**Output**
lighttpd/1.4.67 (ssl) - a light and fast webserver
Configure Firewall For Lighttpd
Assuming you have already enabled firewalld
, you need to allow HTTP and HTTPS traffic through your AlmaLinux firewall:
# sudo firewall-cmd --permanent --zone=public --add-service=http
# sudo firewall-cmd --permanent --zone=public --add-service=https
Reload the firewall to apply the new rules:
sudo firewall-cmd --reload
Now, access the Lighttpd default page by entering your server’s IP address into your web browser:
http://<mark>Your-IP-addr</mark>
2. Install MariaDB For Lighttpd Web Server
In this setup, MariaDB will serve as the database engine. Install it using the following command:
sudo dnf install mariadb mariadb-server -y
Once the installation is complete, start and enable the MariaDB service:
# sudo systemctl start mariadb.service
# sudo systemctl enable mariadb.service
Confirm that MariaDB is running:
sudo systemctl status mariadb.service
The output should indicate that the service is active:
Secure your MariaDB installation by running:
sudo mysql_secure_installation
This script prompts you to set a new root password, remove anonymous users, disable remote root login, remove the test database, and reload the privilege tables.
3. Install and Configure PHP For Lighttpd Web Server
Install PHP and PHP-FPM, essential for running PHP applications with Lighttpd, using:
sudo dnf install php php-mysqlnd php-pdo php-gd php-mbstring php-fpm lighttpd-fastcgi -y
Open the php-fpm
configuration file using your preferred text editor (like Vi Editor or Nano Editor):
sudo vi /etc/php-fpm.d/www.conf
Locate the user
and group
lines and modify their values to lighttpd
:
PHP-FPM typically uses a Unix socket: listen = /run/php-fpm/www.sock
. Change this to a TCP connection: listen = 127.0.0.1:9000
.
Save and close the file. Then, start and enable the PHP-FPM service:
# sudo systemctl start php-fpm.service
# sudo systemctl enable php-fpm.service
Verify that PHP-FPM is running correctly:
sudo systemctl status php-fpm.service
4. Enable FastCGI support in PHP and Lighttpd Web Server
Enable PHP and PHP-FPM with FastCGI for Lighttpd. First, open the /etc/php.ini
file:
sudo vi /etc/php.ini
Find the line cgi.fix_pathinfo=1
and uncomment it by removing the semicolon (;
).
Save and close the file.
Next, open /etc/lighttpd/modules.conf
:
sudo vi /etc/lighttpd/modules.conf
Uncomment the line:
include conf_dir + "conf.d/fastcgi.conf"
Save and close the file. Finally, open /etc/lighttpd/conf.d/fastcgi.conf
:
sudo vi /etc/lighttpd/conf.d/fastcgi.conf
Add the following lines to the end of the file:
fastcgi.server += ( ".php" =>
((
"host" => "127.0.0.1",
"port" => "9000",
"broken-scriptfilename" => "enable"
))
)
Save and close the file.
Restart the Lighttpd service to apply the changes:
sudo systemctl restart lighttpd
To test the configuration, create a phpinfo.php
file in the /var/www/lighttpd/
directory:
sudo vi /var/www/lighttpd/phpinfo.php
Add the following code to the file:
<?php
phpinfo();
?>
Save and close the file.
Now, navigate to the following URL in your web browser to test FastCGI support:
http://<mark>Your-IP-addr</mark>/phpinfo.php
Conclusion
Lighttpd is an excellent web server for handling high-traffic websites that demand speed and efficiency. You’ve now successfully learned how to Install Lighttpd on AlmaLinux 9.
We hope you found this guide helpful. You might also be interested in these related 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
Alternative Solutions to Installing Lighttpd on AlmaLinux 9
While the EPEL repository method is effective, other approaches exist for installing Lighttpd on AlmaLinux 9. Here are two alternative methods:
1. Using Remi Repository
The Remi repository provides more recent versions of PHP and related software than the default AlmaLinux repositories. If you require a newer PHP version compatible with Lighttpd, using Remi is a viable option.
Explanation: Remi Collet maintains the Remi repository, which offers newer PHP versions, MariaDB, and other packages often not available in the base AlmaLinux repositories or EPEL. This repository is particularly useful for developers who need the latest features and bug fixes in PHP.
Steps:
-
Install Remi Repository:
First, enable the Remi repository. You might need to install
yum-utils
first.sudo dnf install yum-utils -y sudo dnf config-manager --enable remi-php82 # Example for PHP 8.2
Replace
remi-php82
with the specific PHP version you need (e.g.,remi-php81
,remi-php83
). -
Install Lighttpd and PHP:
Now, install Lighttpd and the desired PHP version along with necessary extensions. This will use the PHP version from Remi repository.
sudo dnf install lighttpd php php-fpm php-mysqlnd php-pdo php-gd php-mbstring lighttpd-fastcgi -y
-
Configure PHP-FPM:
Follow the same PHP-FPM configuration steps outlined in the original article, ensuring that the user and group are set to
lighttpd
and that thelisten
directive is configured correctly. -
Enable FastCGI:
Also, follow the FastCGI configuration steps to ensure Lighttpd can properly handle PHP requests.
2. Compiling from Source
Compiling Lighttpd from source gives you the most control over the installation process and allows you to customize the server with specific compile-time options.
Explanation: Compiling from source involves downloading the Lighttpd source code, configuring the build process with desired options, and then compiling and installing the software. This method is suitable for advanced users who need specific customizations or who want to use the very latest, unreleased version of Lighttpd. It also allows you to choose specific modules and dependencies to include.
Steps:
-
Install Dependencies:
Install the necessary build tools and libraries required to compile Lighttpd.
sudo dnf install gcc make automake autoconf libtool pcre-devel openssl-devel bzip2-devel zlib-devel -y
-
Download Source Code:
Download the latest Lighttpd source code from the official Lighttpd website or a trusted mirror.
wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.69.tar.gz #Replace with the current version tar -xvzf lighttpd-1.4.69.tar.gz cd lighttpd-1.4.69
-
Configure and Compile:
Configure the build using
./configure
with appropriate options, then compile usingmake
../configure --prefix=/usr/local/lighttpd --with-openssl --with-pcre make
Customize the
--prefix
option to specify the installation directory. Other options can be added to enable specific modules. -
Install Lighttpd:
Install the compiled Lighttpd binaries.
sudo make install
-
Configure Lighttpd:
Create necessary configuration files in
/usr/local/lighttpd/etc/
, and start Lighttpd.
You’ll need to manually create the service file in/etc/systemd/system/
and enable it using systemctl.A sample systemd service file
lighttpd.service
might look like this:[Unit] Description=Lighttpd Web Server After=network.target [Service] ExecStart=/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf Restart=on-failure [Install] WantedBy=multi-user.target
Then enable and start the service.
sudo systemctl enable lighttpd.service sudo systemctl start lighttpd.service
These alternative methods provide flexibility depending on your specific requirements for Install Lighttpd on AlmaLinux 9, particularly regarding PHP versions and customization options. Remember to adjust configurations and dependencies according to your needs. These detailed steps enable you to choose the most suitable installation method for your specific environment and skill level.