Install Lighttpd on AlmaLinux 9: Best Web Server – OrcaCore

Posted on

Install Lighttpd on AlmaLinux 9: Best Web Server - OrcaCore

Install Lighttpd on AlmaLinux 9: Best Web Server – OrcaCore

This guide provides a comprehensive walkthrough on how to Install Lighttpd on AlmaLinux 9. Lighttpd, a lightweight and high-performance open-source web server (licensed under the revised BSD license), was created by Jan Kneschke. Its speed and efficiency make it an attractive alternative to heavier web servers like Apache.

Lighttpd boasts IPv4 and IPv6 compatibility and understands HTTP/1.0 and 1.1, HTTPS (using OpenSSL), CGI/1.1, native FastCGI, and HTTP authentication. It supports features such as virtual hosts, directory listings, streaming CGI and FastCGI, URL-Rewriting, HTTP-Redirects, output-compression with transparent caching, automatic expiration of files, and Large File support.

Lighttpd shines particularly with PHP. It often equals or surpasses the performance of Apache + mod_php4 while effectively handling various PHP bugs in the FastCGI SAPI. Follow the steps below from Orcacore to complete the Lighttpd setup on your AlmaLinux 9 system.

Before you begin, ensure you are logged in to your server as a non-root user with sudo privileges and have a basic firewall configured. Refer to our article on Initial Server Setup with AlmaLinux 9 for detailed instructions.

1. Install Lighttpd on AlmaLinux 9

The primary method to Install Lighttpd on AlmaLinux 9 involves utilizing the EPEL (Extra Packages for Enterprise Linux) repository. Start by updating your local package index:

sudo dnf update -y

Next, install the EPEL release repository on AlmaLinux 9:

sudo dnf install epel-release -y

Now, install Lighttpd itself:

sudo dnf install lighttpd -y

Start and Enable Lighttpd Service

Start and enable the Lighttpd service to ensure it starts automatically at boot time:

# sudo systemctl start lighttpd
# sudo systemctl enable lighttpd

Verify that the Lighttpd service is active and running:

sudo systemctl status lighttpd

The output should resemble the following:

Lighttpd service status

You can also check the Lighttpd version installed on your AlmaLinux 9 system:

lighttpd -v

The output will display the version information:

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

Configure Firewall For Lighttpd

Assuming you have firewalld enabled, you need to allow HTTP and HTTPS traffic through the firewall:

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

Reload the firewall to apply these changes:

sudo firewall-cmd --reload

Now, you can access the default Lighttpd page by entering your server’s IP address in your web browser:

http://<mark>Your-IP-addr</mark>

2. Install MariaDB For Lighttpd Web Server

This setup uses MariaDB as the database engine. To install it, execute 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 active and running:

sudo systemctl status mariadb.service

The output should indicate that the service is active.

MariaDB service status for Lighttpd

Secure your MariaDB installation:

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

Now, install PHP and PHP-FPM (FastCGI Process Manager) for Lighttpd:

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

Open the php-fpm configuration file using a text editor (like Vi or Nano):

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

Locate the user and group lines and change their values to lighttpd:

Change user and group to Lighttpd

PHP-FPM defaults to using a socket listen = /run/php-fpm/www.sock. Change this to a TCP connection by modifying the line to listen = 127.0.0.1:9000:

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

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 active and running:

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

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

Look for the line include conf_dir + "conf.d/fastcgi.conf" and uncomment it.

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 at 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 PHP code to the file:

<?php
phpinfo();
?>

Save and close the file.

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 choice for serving websites that demand speed and efficiency, especially under heavy traffic. This guide has shown you how 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

Alternative Solutions for Installing Lighttpd on AlmaLinux 9

While the EPEL repository method is common, here are two alternative approaches to Install Lighttpd on AlmaLinux 9:

1. Using Remi Repository

Remi repository is another popular third-party repository that often contains more up-to-date versions of PHP and related packages, which can be advantageous if you require specific PHP versions or features not readily available in the base AlmaLinux or EPEL repositories.

Explanation:

The Remi repository is known for providing more recent versions of PHP and related packages compared to the base AlmaLinux and EPEL repositories. By enabling and using the Remi repository, you gain access to newer PHP versions and their corresponding modules, which can be beneficial for applications requiring specific PHP functionalities or performance enhancements.

Steps:

  1. Install Remi Repository:

    sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm
  2. Enable Remi Repository (for PHP 8.2, for example):
    Choose the PHP version you want.

    sudo dnf module enable php:remi-8.2
  3. Install Lighttpd and PHP:

    sudo dnf install lighttpd php php-fpm php-mysqlnd
  4. Configure PHP-FPM as outlined in the original guide. Follow steps 3 and 4 from the previous instructions to configure php-fpm.d/www.conf, enable FastCGI, and test the configuration. This ensures that Lighttpd properly interacts with PHP-FPM.

This approach allows you to leverage the Remi repository for more recent PHP versions, giving you flexibility and access to the latest features and improvements.

2. Compiling from Source

For advanced users who require highly customized configurations or the absolute latest version of Lighttpd, compiling from source is an option.

Explanation:

Compiling from source grants you complete control over the build process, enabling you to fine-tune compilation options, apply specific patches, and integrate custom modules. This approach is suitable for users with specialized requirements that cannot be met through pre-built packages.

Steps:

  1. Install Development Tools and Dependencies:

    sudo dnf groupinstall "Development Tools"
    sudo dnf install pcre-devel bzip2-devel openssl-devel zlib-devel libtool autoconf automake
  2. Download the Lighttpd Source Code:
    Find the latest stable version on the Lighttpd website. Then:

    wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.70.tar.gz
    tar -xzf lighttpd-1.4.70.tar.gz
    cd lighttpd-1.4.70
  3. Configure, Build, and Install:

    ./configure --prefix=/usr/local/lighttpd --with-openssl --with-pcre --with-zlib --with-bzip2
    make
    sudo make install
  4. Create a Systemd Service File:
    Create /etc/systemd/system/lighttpd.service with the following content:

    [Unit]
    Description=Lighttpd Web Server
    After=network.target
    
    [Service]
    ExecStart=/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/lighttpd.conf
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
  5. Enable and Start the Service:

    sudo systemctl enable lighttpd
    sudo systemctl start lighttpd
  6. Configure Lighttpd and PHP-FPM:
    You’ll need to manually configure Lighttpd to work with PHP-FPM. This involves editing /usr/local/lighttpd/lighttpd.conf and ensuring the FastCGI module is enabled and configured correctly. Example configuration:

    server.modules = (
            "mod_access",
            "mod_alias",
            "mod_compress",
            "mod_redirect",
            "mod_fastcgi",
    )
    
    server.document-root        = "/var/www/lighttpd/"
    server.upload-dirs          = ( "/tmp" )
    server.errorlog             = "/var/log/lighttpd/error.log"
    server.pid-file             = "/run/lighttpd.pid"
    server.username             = "lighttpd"
    server.groupname            = "lighttpd"
    
    index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
    
    fastcgi.server = ( ".php" =>
            (
                    (
                            "host" => "127.0.0.1",
                            "port" => "9000",
                            "broken-scriptfilename" => "enable"
                    )
            )
    )

    Ensure that /var/www/lighttpd exists and is owned by the lighttpd user. You may need to create the user and group lighttpd if they don’t already exist.

This approach gives you maximum control but requires a deeper understanding of the software and build process. Remember to adjust the paths according to your actual installation location. Also, note that compiling from source requires you to manually handle updates and security patches.

By exploring these alternative methods, you can choose the installation approach that best aligns with your requirements and expertise when you Install Lighttpd on AlmaLinux 9. Each method provides a unique level of control and customization, enabling you to tailor your Lighttpd installation to specific needs.

Leave a Reply

Your email address will not be published. Required fields are marked *