Lighttpd is a fast, lightweight, secure, and flexible web server specially designed for mission-critical environments. Compared to other web servers like Apache and Nginx, Lighttpd offers lower memory and CPU usage. It supports several technologies, including PHP, FastCGI, Auth, SSL, URL rewriting, reverse proxy, load balancing, and much more. It has a small memory footprint and is capable of handling many concurrent connections. It is cross-platform and can be installed on Unix, Linux, and Windows systems.

In this post, we will show you how to install a Lighttpd web server on Oracle Linux 8.

Step 1 – Install Lighttpd

By default, Lighttpd is not included in the Oracle Linux 8 default repo, so you will need to install the EPEL repository on your server. You can install it with the following command:

dnf update -y
dnf install epel-release

Once the EPEL repo is installed, install the Lighttpd package using the following command:

dnf install lighttpd

After the successful installation, start and enable the Lighttpd service with the following command:

systemctl start lighttpd
systemctl enable lighttpd

You can check the status of Lighttpd using the following command:

systemctl status lighttpd

You should get the following output:

● lighttpd.service - Lightning Fast Webserver With Light System Requirements
   Loaded: loaded (/usr/lib/systemd/system/lighttpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-08-23 08:28:12 EDT; 5s ago
 Main PID: 25076 (lighttpd)
    Tasks: 1 (limit: 11409)
   Memory: 1.2M
   CGroup: /system.slice/lighttpd.service
           └─25076 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf

Aug 23 08:28:12 oraclelinux8 systemd[1]: Started Lightning Fast Webserver With Light System Requirements.
Aug 23 08:28:12 oraclelinux8 lighttpd[25076]: 2022-08-23 08:28:12: (server.c.1404) can't have more connections than fds/2:  1024 1024

You can also verify the Lighttpd version with the following command:

lighttpd -v

You should get the following output:

lighttpd/1.4.55 (ssl) - a light and fast webserver

Now, open your web browser and access the Lighttpd test page using the URL http://your-server-ip. You should see the following page:
Lighttpd test page

Step 2 – Install MariaDB Database Server

By default, the MariaDB server package is included in the Oracle Linux 8 default repo. You can install it with the following command:

dnf install mariadb mariadb-server

Once MariaDB is installed, start and enable the MariaDB service using the following command:

systemctl start mariadb.service
systemctl enable mariadb.service

To check the MariaDB status, run the following command:

systemctl status mariadb.service

You will get the following output:

● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-08-23 01:41:47 EDT; 6h ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 3904 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 62 (limit: 11409)
   Memory: 128.8M
   CGroup: /system.slice/mariadb.service
           └─3904 /usr/libexec/mysqld --basedir=/usr

Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: See the MariaDB Knowledgebase at http://mariadb.com/kb or the
Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: MySQL manual for more instructions.
Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: Please report any problems at http://mariadb.org/jira
Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: The latest information about MariaDB is available at http://mariadb.org/.
Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: You can find additional information about the MySQL part at:
Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: http://dev.mysql.com
Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: Consider joining MariaDB's strong and vibrant community:
Aug 23 01:41:47 oraclelinux8 mysql-prepare-db-dir[3801]: https://mariadb.org/get-involved/
Aug 23 01:41:47 oraclelinux8 mysqld[3904]: 2022-08-23  1:41:47 0 [Note] /usr/libexec/mysqld (mysqld 10.3.32-MariaDB) starting as process 3904>
Aug 23 01:41:47 oraclelinux8 systemd[1]: Started MariaDB 10.3 database server.

Step 3 – Install PHP and PHP-FPM with FastCGI

To install PHP with PHP-FPM and FastCGI support, you need to install PHP with some required extensions. You can install all of them by running the following command:

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

Next, find the following line:

;listen = /run/php-fpm/www.sock

And replace it with the following line:

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:

systemctl start php-fpm
systemctl enable php-fpm

Step 4 – Enable PHP and PHP-FPM Support in Lighttpd

To enable FastCGI support in PHP, edit the php.ini configuration file:

nano /etc/php.ini

Change the following line:

cgi.fix_pathinfo=1

Next, edit the /etc/lighttpd/modules.conf file:

nano /etc/lighttpd/modules.conf

Uncomment the following line:

include "conf.d/fastcgi.conf"

Next, edit the /etc/lighttpd/conf.d/fastcgi.conf file.

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:

systemctl restart lighttpd
systemctl restart php-fpm

Step 5 – Verify the Lighttpd Server

Next, you will need to create a phpinfo.php configuration file to test the FastCGI support in PHP.

nano /var/www/lighttpd/phpinfo.php

Add the following code:

<?php
phpinfo();
?>

Save and close the file. Then, open your web browser and access your PHP test page using the URL http://your-server-ip/phpinfo.php. You should see your PHP test page on the following screen:
PHP test page

Conclusion

Congratulations! You have successfully installed the Lighttpd server with PHP and FastCGI support on Oracle Linux 8. You can now start deploying your web application on your secure and fast Lighttpd server. Get started with Lighttpd on VPS Hosting from Atlantic.Net!