Home / How To / How to install Lighttpd with PHP-FPM and MariaDB on CentOS 8

How to install Lighttpd with PHP-FPM and MariaDB on CentOS 8



Lighttpd is an open source web server that focuses on simplicity and high performance. It is a lightweight web server with low and low memory consumption, but still maintains standard requirements, security and flexibility. Lighttpd web servers are part of LLMP Stack, which stands for Linux, Lighttpd, MySQL / MariaDB and PHP / PHP-FPM.

In this tutorial we will show you how to install and configure LLMP Stack on CentOS 8 Server. We will install the Lighttpd web server using the MariaDB database server and PHP-FPM on the latest version of the CentOS 8 server.

conditions

  • CentOS 8 server
  • Red privileges
  • Understand basic CentOS server

What should we do?

  • Install Lighttpd Web Server
  • Install MariaDB database server
  • Install PHP-FPM
  • Setting Lighttpd and PHP-FPM
  • Testing

Step 1 – Install Lighttpd Web Server

First we add the EPEL layer and install the Lighttpd web server to our CentOS 8 system. By default, Lighttpd is available on the EPEL (Extract Packages for Enterprise Linux) repository.

Add the EPEL layer to the CentOS 8 system using the DNF command below.

sudo dnf install epel-release

Then check all available repositories with the following command.

dnf repolist

Make sure you get the EPEL stock on the result.

Install EPEL Repository CentOS 8

Then install Lighttpd package with the command below.

sudo dnf install lighttpd -y

When all installation is complete, start the Lighttpd service and add it to the system boot.

systemctl start lighttpd
systemctl enable lighttpd

Now check the Lighttpd service status with the following command.

systemctl status lighttpd

Below you see the result.

Install Lighttpd on CentOS 8

As a result, the Lighttpd service is running on the CentOS 8 system.

Then add the HTTP service to the list of firewall rule using the ‘firewall cmd’ command below.

firewall-cmd --add-service=http --permanent
firewall-cmd --reload

Now open your browser and enter the server’s IP address in the address bar.

http://192.168.1.50/

As a result, you get the default ‘index.html’ for the Lighttpd web server.

Lighttpd index.html

Step 2 – Install MariaDB Database Server

In this step, we will install the MariaDB database server and set the default password for the MariaDB server.

Run the dnf command below to install the MariaDB database server.

sudo dnf install mariadb-server -y

When all installation is complete, start the MariaDB service and add it to the system boot.

systemctl start mariadb
systemctl enable mariadb

Now check the MariaDB service with the command below.

systemctl status mariadb

Below you see the result.

Launch MySQL Service

As a result, the MariaDB service is up and running with the CentOS 8 system.

Then run the command ‘mysql_secure_installation’ below to set the default password.

mysql_secure_installation

Now enter the new password for your MariaDB server and type “Y” for all configurations.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Set a root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

And the MariaDB root password has been configured.

Then log in to the MySQL shell with the default user and your password.

mysql -u root -p

After logging in, check all available users on the MariaDB server using the following questions.

select User,Host from mysql.user;

And you get all the default users for MySQL server. Now type ‘exit’ to log out of the MySQL shell.

As a result, the installation and configuration of the MariaDB database server on the CentOS 8 system has been completed.

Step 3 – Install and configure PHP-FPM

In this step, we will install and configure PHP-FPM for Lighttpd web server.Advertisement

Install PHP and PHP-FPM packages using the dnf command below.

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

When all installation is complete, you can edit the configuration ‘/etc/php-fpm.d/www.conf’ with the vim editor.

vim /etc/php-fpm.d/www.conf

Change default ‘users’ and ‘group’ to Lighttpd as below.

user = lighttpd
group = lighttpd

Change the default PHP-FPM listen with the local IP address with port ‘9000’.

listen = 127.0.0.1:9000

Save and close.

Then edit the PHP configuration ‘/etc/php.ini’ with the vim editor.

vim /etc/php.ini

Uncheck the following line to get PHP-CGI support for the Lighttpd web server.

cgi.fix_pathinfo=1

Save and close.

Then start the PHP-FPM service and add it to the system boot.

systemctl start php-fpm
systemctl enable php-fpm

Configure PHP-FPM service

The PHP-FPM service is running, check with the following command.

ss -plnt
systemctl status php-fpm

Below you see the result.

Check PHP-FPM Service

As a result, PHP-FPM is running on the CentOS 8 server with the local IP address and ‘9000’ port.

Step 4 – Setting Lighttpd and PHP-FPM

In this step, we configure Lighttpd to work with our PHP-FPM installation.

By default, Lighttpd can be used to serve PHP web application in two ways:

  1. Serve via PHP-FPM Service
  2. Serve through self-pouring PHP-CI

To do this, we need to enable the FastCGI module on the Lighttpd web server and add our configuration to the FastCGI module configuration file.

– Activate FastCGI module

Before going any further, go to the directory ‘/ etc / lighttpd /’ and edit the configuration ‘modules.conf’ with the vim editor.

cd /etc/lighttpd/
vim modules.conf

Deselect the “FastCGI” module as shown below.

##
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"

Save and close.

Then we need to add our PHP configuration to the configuration file ‘conf.d / fastcgi.conf’.

Inside the directory ‘/ etc / lighttpd’, edit the FastCGI configuration ‘conf.d / fastcgi.conf’ with the vim editor.

vim conf.d/fastcgi.conf

– To use with PHP-FPM Service

To use the PHP-FPM service, which is already running at the local IP address using TCP port ‘9000’, paste the following configuration.

fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

Save and close.

– Use self-spreading PHP service

Next, if you want to use the self-casting PHP-CGI for Lighttpd, paste the following configuration into it.

fastcgi.server = ( ".php" => 
        ((
                "bin-path" => "/usr/bin/php-cgi",
                "socket" => "/var/run/lighttpd/php.socket",
                "max-procs" => 4,
                "bin-environment" => (
                "PHP_FCGI_CHILDREN" => "",
                "PHP_FCGI_MAX_REQUESTS" => "500"
                    ),
                "broken-scriptfilename" => "enable"
        ))
)

Save and close.

Then create a new directory ‘/ var / run / lighttpd’ and change the ownership of that directory to the ‘lighttpd’ user.

mkdir -p /var/run/lighttpd
sudo chown -R lighttpd:lighttpd /var/run/lighttpd

Restart the Lighttpd service to apply the new configuration.

systemctl restart lighttpd

Make sure there is no error, and as a result, the configuration of Lighttpd with PHP-FPM Service or using spawning PHP-CGI is complete.

Configure Lighttpd with PHP-FPM

Step 5 – Test

To test our LLMP installation, we will create a new phpinfo file in the default Lighttpd Document Root directory.

Go to the directory ‘/ var / www / lighttpd’ and create a new php file ‘info.php’ with the vim editor.

cd /var/www/lighttpd/
vim info.php

Paste the following script into it.

phpinfo();
?>

Save and close.

Create PHPINFO file to test LLMP Stack Installation

Then open your browser and type the server’s IP address followed by the file “info.php” as below.

http://192.168.1.50/info.php

Now you get the result as below.

phpinfo

As shown, PHP-FPM works with the Lighttpd web server.

As a result, the installation of LLMP Stack (Linux, Lighttpd, MariaDB and PHP-FPM) has been completed on CentOS 8 Server.

Step 6 – Additional: Check PHP and Lighttpd services

If you are running Lighttpd with slef-spawned PHP service using the configuration below.

Lighttpd with PHP self-spawned service

You can check the PHP service with the command below.

ss -pl | grep php
systemctl status php-fpm

Below you see the result.

Lighttpd with PHP Self-Spawned Service

As you can see, the self-spawning PHP process runs under four socket files. Although the PHP-FPM service is down, Lighttpd still works to process PHP applications.


Source link