The LLMP Stack (Linux, Lighttpd, MariaDB, and PHP-FPM) is a software stack for delivering web applications. Each component of the LLMP Stack is free, open-source, and can be installed on multiple operating systems. The LLMP Stack can deliver static HTML sites and PHP applications like WordPress, Drupal, and Joomla.

This tutorial will show you how to install and configure the LLMP Stack (Linux, Lighttpd, MariaDB, and PHP-FPM) on the latest Ubuntu 22.04 system. This tutorial includes instructions on how to set up the Virtual Host on the Lighttpd web server and enable SSL/HTTPS.

Prerequisites

For this tutorial, we will need the following prerequisites:

  • An Ubuntu 22.04 server.
  • A non-root user with root/administrator privileges

Installing Lighttpd Web Server

Lighttpd or Lighty is a high-performance web server created as the proof-of-concept of the c10k problem “how to handle 10,000 connections in parallel one single server”.

The Lighttpd is designed for speed, security, light weight and flexibility. It has minimal CPU and memory usage and provides advanced features such as FastCGI, CGI, Auth, Compression, URL Rewriting, and more.

Before installing any package, run the apt command below to update and refresh the package index of your Ubuntu repositories.

sudo apt update

Now install the Lighttpd web server using the following command.

sudo apt install lighttpd

Input Y to confirm the installation and press ENTER to continue. Now the Lighttpd installation will begin.

<img alt="install lighttpd" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/1-install-lighttpd.png6619668b413c7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="341" loading="lazy" src="data:image/svg xml,” width=”747″>

After Lighttpd installation is finished, run the command below to start and enable the Lighttpd service.

sudo systemctl start lighttpd

sudo systemctl enable lighttpd

Check and verify the Lighttpd service using the command below. You should see the Lighttpd service is running and enabled, which means it will be automatically running at system boot.

sudo systemctl status lighttpd

<img alt="start lighttpd" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/2-start-lighttpd.png6619668b72099.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="281" loading="lazy" src="data:image/svg xml,” width=”750″>

If you have a UFW firewall running on your Ubuntu machine, then you must add the firewall rules for incoming traffic to the Lighttpd web server.

Run the ufw command below to add the Lighttpd rules to the UFW firewall, then you can check and verify the list of the UFW rules as below.

sudo ufw allow "Lighttpd Full"

sudo ufw status

You should see the application profile “Lighttpd Full” added to the UFW firewall, which means all incoming HTTP and HTTPS ports are allowed.

<img alt="setup ufw firewall" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/3-setup-ufw-firewall.png6619668b9c222.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="297" loading="lazy" src="data:image/svg xml,” width=”578″>

Now check the directory “/var/www/html” using the below command. If you don’t see an index.html file, you can create one using the command below.

ls -lah /var/www/html

echo "

Welcome to Lighttpd Web Server

" > /var/www/html/index.html

Lastly, open up your web browser and visit the server IP address (i.e http://192.168.5.28/) and you should see the index.html page.

<img alt="lighttpd index" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/4-lighttpd-index.png6619668bc2981.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="149" loading="lazy" src="data:image/svg xml,” width=”750″>

Installing MariaDB Server

After installing the Lighthttpd web server, installing the MariaDB server to the Ubuntu system is time. This also includes how to deploy the MariaDB server securely using the “mysql_secure_installation” tool provided by the MariaDB package.

Run the following apt command to install the MariaDB server. At the current state, the default Ubuntu repository provides the MariaDB v10.6.

sudo apt install mariadb-server

Now input Y to confirm the installation and press ENTER. And the MariaDB installation will begin.

<img alt="install mariadb" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/10-install-mariadb.png6619668c045f8.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="355" loading="lazy" src="data:image/svg xml,” width=”750″>

After the MariaDB installation is finished, run the systemctl command below to start and enable the MariaDB service.

sudo systemctl start mariadb

sudo systemctl enable mariadb

Check and verify the MariaDB service using the following command. And you should see the MariaDB service running.

sudo systemctl status mariadb

Next, you will set up the MariaDB deployment using the “mysql_secure_instalaltion” tool, which can help you to set up the root password for the MariaDB server, and disable remote root login, clean up default database and anonymous user access, etc.

Now run the “mysql_secure_installation” command as below.

sudo mysql_secure_installation

The default MariaDB installation comes without a root password. Press ENTER to continue.

<img alt="mysql_secure_installation" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/11-setup-mariadb-password.png6619668c2ee63.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="192" loading="lazy" src="data:image/svg xml,” width=”688″>

Now input “n” to keep the authentication method as default (for the MariaDB root user).

<img alt="no unix_socket auth for root" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/12-no-unix-socket-auth.png6619668c58294.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="152" loading="lazy" src="data:image/svg xml,” width=”731″>

Input Y to set up the root password for your MariaDB server. Be sure to use a strong password for your deployment.

<img alt="setup root password" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/13-create-new-password.png6619668c823c4.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="180" loading="lazy" src="data:image/svg xml,” width=”717″>

Now input Y to disable the remote login for the MariaDB root user. If you are not in a cluster environment, it’s always recommended to disable remote login for the MariaDB root user.

<img alt="disable remote login" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/15-disable-root-remote-login.png6619668ca6bb5.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="127" loading="lazy" src="data:image/svg xml,” width=”688″>

Now input Y again to remove the default anonymous user from your MariaDB installation.

<img alt="remove anonymous user" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/14-remove-anonymous-user.png6619668cdea22.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="178" loading="lazy" src="data:image/svg xml,” width=”693″>

Input Y again to remove the default database test accessible by the anonymous user on MariaDB.

<img alt="remove database test" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/16-remove-database-test.png6619668d1429c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="194" loading="lazy" src="data:image/svg xml,” width=”683″>

Lastly, input Y again to reload all table privileges on your MariaDB server and apply new changes.

<img alt="reload tables privileges" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/17-reload-table-privileges.png6619668d3fd2e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="266" loading="lazy" src="data:image/svg xml,” width=”709″>

Installing PHP-FPM 8.1

You have now installed the Lighttpd web server and MariaDB database server. Now you will be installing the PHP-FPM on your Ubuntu system. At the current state, the Ubuntu repository provides the latest version of PHP 8.1.

Run the apt command below to install PHP-FPM 8.1 on your Ubuntu system.

sudo apt install php-fpm php-common php-mysql php-cli php-curl php-xml

Input Y to confirm the installation and press ENTER. Now, the installation will begin.

<img alt="install php-fpm" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/5-install-php-fpm.png6619668d6a41d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="255" loading="lazy" src="data:image/svg xml,” width=”750″>

After the PHP-FPM packages installation is completed, run the below command to start and enable the PHP-FPM service.

sudo systemctl start php8.1-fpm

sudo systemctl enable php8.1-fpm

Check and verify the PHP-FPM service using the below command. You should see the PHP-FPM service is running.

sudo systemctl status php8.1-fpm

<img alt="start php-fpm" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/6-start-php-fpm.png6619668db892c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="279" loading="lazy" src="data:image/svg xml,” width=”750″>

You can also check the PHP-FPM service using the “ss” command. The default PHP-FPM process runs under the sock file, and you can check the PHP-FPM process using the command below.

ss -pl | grep php

You should get the PHP-FPM service running on the sock file “/run/php/php8.1-fpm.sock“.

<img alt="check php-fpm" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/7-check-php-fpm.png6619668deb653.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="139" loading="lazy" src="data:image/svg xml,” width=”750″>

Configuring PHP-FPM with Lighttpd

The installation of LLMP Stack packages is completed, but you still need to set up the Lighttpd web server so it can work with the PHP-FPM service. And this can be done by using the FastCGI modules on the Lighttpd web server.

First, edit the PHP-FPM configuration file “/etc/php/8.1/fpm/php.ini” using nano editor.

sudo nano /etc/php/8.1/fpm/php.ini

Add the following configuration to the file.

cgi.fix_pathinfo = 1

Save and close the file when you are done.

Now restart the PHP-FPM service using the below command to apply new changes.

sudo systemctl restart php8.1-fpm

Next, run the following command to enable Lighttpd “fastcgi” and “fastcgi-php-fpm” modules.

sudo lighty-enable-mod fastcgi fastcgi-php-fpm

Edit the configuration file “/etc/lighttpd/conf-available/15-fastcgi-php-fpm.conf” using nano editor. This file is the fastcgi-php-fpm module configuration that will be used to communicate with PHP-FPM sock file.

sudo nano /etc/lighttpd/conf-available/15-fastcgi-php-fpm.conf

Change the path of the socket option to “/run/php/php8.1-fpm.sock” as the following.

## Use PHP-FPM service for PHP via FastCGI

fastcgi.server = ( ".php" =>

        ((

                "socket" => "https://www.howtoforge.com/run/php/php8.1-fpm.sock",

                "broken-scriptfilename" => "enable"

        ))

)

Save and close the file when you are done.

Lastly, run the command below to restart the Lighttpd service and apply new changes. Now your LLMP Stack is ready to serve both static HTML and dynamic PHP web applications

sudo systemctl restart lighttpd

<img alt="configure php-fpm lighttpd" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/8-configure-php-fpm-lighttpd.png6619668e1d859.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="188" loading="lazy" src="data:image/svg xml,” width=”750″>

Testing Phpinfo

To verify your LLMP Stack installation, you can simply create the PHPINFO script that shows you the detailed configuration of Lighttpd and PHP-FPM configurations.

Run the command below to create a new PHP script “/var/www/html/info.php” and change the ownership to the “www-data” user.

echo "" > /var/www/html/info.php

sudo chown -R www-data:www-data /var/www/html

Back to your web browser and visit the Ubuntu server IP address followed by the URL path “/info.php” (http://192.168.5.28/info.php). And you should see the detailed phpinfo page in the following screenshot. This means the Lighttpd and PHP-FPM configuration is completed and successful.

<img alt="php info llmp" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/9-phpinfo-llmp.png6619668e6f69a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="747" loading="lazy" src="data:image/svg xml,” width=”750″>

Setup Virtual Host on Lighttpd

At this point, you have completed the LLMP Stack installation and configuration. The LLMP Stack is also ready to server a dynamic PHP web application through PHP-FPM. Now you will learn how to set up the Virtual Host on the Lighttpd web server. The Virtual host allows you to run multiple domain names on a single server or IP address.

Now run the following command to create a new directory “/etc/lighttpd/vhosts“. This directory will be used to store all virtual host configurations of the Lighttpd web server.

sudo mkdir -p /etc/lighttpd/vhosts/

Now edit the Lighttpd configuration file “/etc/lighttpd/lighttpd.conf” using nano editor.

sudo nano /etc/lighttpd/lighttpd.conf

Add the following configuration to the file.

include "https://www.howtoforge.com/etc/lighttpd/vhosts/*.conf"

Save and close the file when you are done. Now you are ready to set up the Lighttpd virtual host.

First, create the Document Root directory for your virtual host. In this example, the Document Root directory will be “/var/www/hwdomain“.

mkdir -p /var/www/hwdomain/

Create a new “index.html” file on the Document root directory “https://www.howtoforge.com/var/www/hwdomain” and change the ownership to the correct user “www-data”.

echo "

Welcome to hwdomain.io virtual host

" > /var/www/hwdomain/index.html

sudo chown -R www-data:www-data /var/www/hwdomain

Next, create a new virtual host configuyration “/etc/lighttpd/vhosts/hwdomain.conf” using nano editor.

sudo nano /etc/lighttpd/vhosts/hwdomain.conf

Add the following configuration to the file. In this example, the domain “hwdomain.io” will be used for the virtual host.

$HTTP["host"] =~ "(^|.)hwdomain.io$" {

    server.document-root = "https://www.howtoforge.com/var/www/hwdomain"

    server.errorlog = "https://www.howtoforge.com/var/log/lighttpd/hwdomain.io-error.log"

    accesslog.filename = "https://www.howtoforge.com/var/log/lighttpd/hwdomain.io-access.log"

}

Save and close the file when you are done.

After that, run the following command to check and verify the Lighttpd configuration. If the Lighttpd configuration is correct, you will see the output message such as “Syntax OK“.

sudo lighttpd -t -f /etc/lighttpd/lighttpd.conf

Now restart the Lighttpd service to apply the new virtual host configuration using the below command.

sudo systemctl restart lighttpd

<img alt="lighttpd virtual host" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/18-configure-virtual-host-lighttpd.png6619668ea91d5.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="153" loading="lazy" src="data:image/svg xml,” width=”750″>

Back to your web browser and input your domain name on the address bar (i.e http://hwdomain.io/). And you should see the default index.html page for that virtual host.

<img alt="lighttpd virtual host" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/19-virtual-host-lighttpd.png6619668ec8c16.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="136" loading="lazy" src="data:image/svg xml,” width=”651″>

Enable HTTPS on Lighttpd Web Server

After setting up the Lighthttpd virtual host, now you will learn how to enable SSL/HTTPS on the Lighttpd web server.

Before starting configuring SSL, run the command below to enable the “ssl” module for the Lighttpd web server. This will create link file to the “/etc/lighttpd/conf-enabled/10-ssl.conf“, which contains the basic SSL configuration for Lighttpd. And also, you will be required to generate the SSL certificates for localhost with the name “server.pem

sudo lighty-enable mod ssl

Now run the below command to create and generate the SSL certificate for localhost with the name “server.pem“.

openssl req -new -newkey rsa:2048 -nodes -keyout server.com.key -out server.com.csr

openssl x509 -req -days 365 -in server.com.csr -signkey server.com.key -out server.com.crt
cat server.com.key server.com.crt > server.pem

And now you are ready to implement the SSL/HTTPS on the virtual host configuration “hwdomain.conf“.

Before starting configuring the SSL for the virtual host, be sure you have generated SSL certificates for your domain name. In this example the domain name is “hwdomain.io” and SSL certificates are available at the “/etc/letsencrypt/live/hwdomain.io” directory.

Edit the virtual host configuration “/etc/lighttpd/vhosts/hwdomain.conf” using nano editor.

sudo nano /etc/lighttpd/vhosts/hwdomain.conf

Replace the configuration that you just created with the following configuration.

$HTTP["scheme"] == "http" {

        $HTTP["host"] == "hwdomain.io" {

                url.redirect = ("https://www.howtoforge.com/.*" => "https://hwdomain.io$0")

        }

}

$SERVER["socket"] == ":443" {

    ssl.engine = "enable"

    ssl.pemfile = "https://www.howtoforge.com/etc/letsencrypt/live/hwdomain.io/fullchain.pem"

    ssl.privkey = "https://www.howtoforge.com/etc/letsencrypt/live/hwdomain.io/privkey.pem"

    server.name = "hwdomain.io"

    server.document-root = "https://www.howtoforge.com/var/www/hwdomain"

    server.errorlog = "https://www.howtoforge.com/var/log/lighttpd/hwdomain.io-error.log"

    accesslog.filename = "https://www.howtoforge.com/var/log/lighttpd/hwdomain.io-access.log"

}

Save and close the file when you are done.

Next, run the following command to check and verify the Lighttpd web server configuration, and be sure you got the output message such as “Syntax OK”. After that, you can restart the Lighttpd service to apply new changes.

sudo lighttpd -t -f /etc/lighttpd/lighttpd.conf

sudo systemctl restart lighttpd

Lastly, go back to your web browser and visit the virtual host domain name with https in front of the URL (i.e., https://hwdomain.io). If your SSL configuration is successful, you will see the local icon on the URL, as shown in the screenshot below.

<img alt="enable SSL/HTTPS Lighttpd" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/04/echo/20-enable-ssl-lighttpd.png6619668eebeec.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="145" loading="lazy" src="data:image/svg xml,” width=”673″>

Conclusion

Congratulation! You have successfully installed the LLMP Stack (Linux, Lighttpd, MariaDB, and PHP-FPM) on the Ubuntu 22.04 server. You have also learned how to set up a virtual host on the Lighttpd web server and enabled the SSL/HTTPS on the Lighttpd for your domain name.