How To Install Linux, Nginx, MariaDB, PHP (LEMP Stack) in RHEL 8


Nginx is an open-source, high-performance web server. It is known for its stability, very simple configuration, rich feature set, and low resource consumption.

Nginx lets you use it as a reverse proxy, load balancer, HTTP cache, and mail proxy.

This post shows you how to install Nginx on RHEL 8 with PHP support (through PHP-FPM) and MariaDB support.

PHP-FPM is an alternative PHP FastCGI implementation. It has additional features that are useful for sites of any size, especially busier sites.

Install Linux

Install Red Hat Enterprise Linux 8 or upgrade from RHEL 7 to RHEL 8.

By now, you should have a Linux system ready with you. Now, we will install Nginx, MariaDB, and PHP-FPM on top of it.

The steps mentioned in this article will only work if you have enabled RHEL 8 subscription or configured the local yum repository on your system.

Log in into the system as the root user or switch to the root user.

$ su -

Install Nginx

In RHEL 8, Nginx is available in the rhel-8-for-x86_64-appstream-rpms repository. So, we do not need to set up the Nginx repository manually.

Install Nginx using the YUM command.

yum -y install nginx

Start the Nginx web server service after the installation.

systemctl start nginx

Check the status Nginx web server service using the below command.

systemctl status nginx
Install LEMP Stack on RHEL 8 - Nginx Web Server Status
Install LEMP Stack on RHEL 8 – Nginx Web Server Status


Allow web requests flow through the firewall by executing the below commands.

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


If you get any error for SELinux on Nginx logs, here is the tutorial on setting SELinux policy for Nginx.

Else, you can temporarily disable the SELinux using the following command. But, we suggest you disable the SELinux permanently.

setenforce 0

Verify Nginx Installation

Open your web browser and visit the below URL.


You should see the following page Welcome to nginx on Red Hat Enterprise Linux. This page confirms you that the Ngnix web server is successfully installed on the server.

Install LEMP Stack on RHEL 8 - Nginx Test Page
Install LEMP Stack on RHEL 8 – Nginx Test Page
The default document root of Nginx on RHEL 8 is /usr/share/nginx/html/. Other configuration files are found under /etc/nginx directory.

Enable the Nginx service at system startup.

systemctl enable nginx

Install MariaDB

Install the MariaDB server using the yum command.

yum -y install mariadb mariadb-server

Start the MariaDB server using the following command.

systemctl start mariadb

Enable the MariaDB service to start automatically during system boot.

systemctl enable mariadb

Once the MariaDB server installation is complete, run the mysql_secure_installation command to secure the MariaDB.


Install PHP

Install the PHP through PHP-FPM (FastCGI Process Manager using YUM command.

yum -y install php-fpm php-mysqlnd php-cli

Edit /etc/php.ini.

vi /etc/php.ini

set cgi.fix_pathinfo to 0.


Edit /etc/php-fpm.d/www.conf file.

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

Make sure the following values are UN-commented.


pm.min_spare_servers = 5	 	 


pm.max_spare_servers = 35	 	 


Change the Listen parameter.


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


listen =

Then, start the PHP-FPM service.

systemctl start php-fpm

Enable PHP-FPM service to start automatically on system boot.

systemctl enable php-fpm

Enable PHP-FPM Support on Virtual Host

We will now create a virtual host on Nginx server for the following details to test the PHP.

Server Name: web.itzgeek.local
Document Root: /usr/share/nginx/html/web.itzgeek.local

Create a configuration file called web.itzgeek.local.conf under /etc/nginx/conf.d and edit it.

vi /etc/nginx/conf.d/web.itzgeek.local.conf

Add the following content.

server {
   server_name web.itzgeek.local;
   root /usr/share/nginx/html/web.itzgeek.local;

   location / {
       index index.html index.htm index.php;

   location ~ \.php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Create a document root directory.

mkdir /usr/share/nginx/html/web.itzgeek.local

For testing the PHP, we will place a PHP file on to the document root of the created virtual host.

echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/web.itzgeek.local/index.php

Restart the services.

systemctl restart nginx

systemctl restart php-fpm

Test LEMP Stack

Create host entry for your web server domain (server.itzgeek.local) in the /etc/hosts (Linux) and hosts file (Windows).             web.itzgeek.local

Open a web browser and enter your domain in the address bar.


The page will look like below.

Install Linux, Nginx, MariaDB, PHP (LEMP Stack) in RHEL 8 - PHP Details
Install Linux, Nginx, MariaDB, PHP (LEMP Stack) in RHEL 8 – PHP Details

From the above screenshot, PHP is working as expected, and it’s working through FPM/FastCGI, as shown in the Server API line.

You can scroll the page further down to see the MariaDB support details.

Install Linux, Nginx, MariaDB, PHP (LEMP Stack) in RHEL 8 - MariaDB Support Details
Install Linux, Nginx, MariaDB, PHP (LEMP Stack) in RHEL 8 – MariaDB Support Details


You have learned how to install LEMP stack on RHEL 8. Please share your feedback in the comments section.

You might also like