Linux MintUbuntu Based

How To Install Lighttpd with MariaDB and PHP-FPM on Linux Mint 21

Install Lighttpd with MariaDB and PHP-FPM on Linux Mint 21

In this tutorial, we will show you how to install Lighttpd with MariaDB and PHP-FPM on Linux Mint 21. Lighttpd is a lightweight, fast, and secure web server that is an excellent alternative to Apache for hosting websites and web applications. When combined with MariaDB, a robust and open-source relational database management system, and PHP-FPM, a high-performance PHP processing engine, you can create a powerful and efficient stack for serving dynamic web content.

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 Lighttpd with MariaDB and PHP-FPM on Linux Mint 21.

Prerequisites

  • A server running one of the following operating systems: Linux Mint 21.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
  • An active internet connection.
  • Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.

Install Lighttpd with MariaDB and PHP-FPM on Linux Mint 21

Step 1. Before proceeding with the installation, it’s crucial to ensure that your Linux Mint 21 system is up to date. Updating the system packages helps in maintaining a secure and stable environment, and it also resolves any potential compatibility issues that may arise during the installation process.

To update your Linux Mint packages, open a terminal and run the following commands:

sudo apt update
sudo apt upgrade

Step 2. Installing Lighttpd Web Server.

 Once the package index is updated, install Lighttpd using the following command:

sudo apt install lighttpd

After the installation is complete, verify that Lighttpd is running by checking its status:

sudo systemctl status lighttpd

If Lighttpd is running correctly, you should see an output indicating that the service is active and running.

To ensure that Lighttpd starts automatically on system boot, enable the service using:

sudo systemctl enable lighttpd

Lighttpd’s configuration files are located in the /etc/lighttpd/ directory, with the main configuration file being lighttpd.conf. The default web root directory is /var/www/html/, where you should place your website files.

Step 3. Installing and Configure MariaDB

Next, install the MariaDB server and client packages with the following command:

sudo apt install mariadb-server mariadb-client

After the installation is complete, secure your MariaDB installation by running the mysql_secure_installation script:

sudo mysql_secure_installation

This script will guide you through setting a root password, removing anonymous users, disabling remote root login, and removing the test database. It is recommended to answer “Y” (yes) to all the prompts for enhanced security.

To access the MariaDB prompt, use the following command:

sudo mysql

From here, you can create a new database and user for your application. Replace your_database, your_username, and your_password with your desired values:

CREATE DATABASE your_database;
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'localhost';
FLUSH PRIVILEGES;
EXIT;

These commands create a new database, a user with a password, and grant the user full privileges on the newly created database.

Step 4. Installing PHP and PHP-FPM.

To install PHP and PHP-FPM, along with the necessary extensions for MariaDB and other common web development tasks, run the following command:

sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-intl php-mbstring php-xml php-zip

Here’s a brief explanation of each PHP extension:

  • php-mysql: Allows PHP to interact with MariaDB databases
  • php-cli: Enables running PHP scripts from the command line
  • php-curl: Provides support for making HTTP requests from PHP
  • php-gd: Adds support for image manipulation and generation
  • php-intl: Enables internationalization features
  • php-mbstring: Handles multi-byte character encoding
  • php-xml: Provides support for parsing and manipulating XML documents
  • php-zip: Allows PHP to read and write ZIP-compressed files

To optimize PHP-FPM for better performance, edit the /etc/php/8.1/fpm/pool.d/www.conf file (replace 8.1 with your PHP version if different) and uncomment the following lines:

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

These settings configure PHP-FPM to dynamically adjust the number of child processes based on the current load, improving resource utilization. After making the changes, restart the PHP-FPM service:

sudo systemctl restart php8.1-fpm

Step 5. Configure Lighttpd to use PHP-FPM.

To enable the FastCGI module in Lighttpd, open the /etc/lighttpd/lighttpd.conf file and uncomment the following line:

include "conf-available/15-fastcgi-php.conf"

Next, edit the /etc/lighttpd/conf-available/15-fastcgi-php.conf file and modify the following lines to match your PHP-FPM socket path:

"socket" => "/run/php/php8.1-fpm.sock",

Create a sample PHP file in the web root directory to test the setup:

echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php

Restart the Lighttpd service for the changes to take effect:

sudo systemctl restart lighttpd

Access the sample PHP file in a web browser by navigating to http://your_server_ip/info.php. If PHP is working correctly, you should see the PHP information page.

Congratulations! You have successfully installed Lighttpd. Thanks for using this tutorial to install the latest version of Lighttpd with MariaDB and PHP-FPM on the Linux Mint system. For additional help or useful information, we recommend you check the official Lighttpd website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button