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 using the below link
READ: Step by Step Guide To Install RHEL 8 with Screenshots
By now, you should have a Linux system ready with you. Now, we will install Nginx, MariaDB, and PHP-FPM on top of it.
Log in into the system as the root user or switch to the root user.
$ su -
Install Nginx
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

Firewall
Allow web requests flow through the firewall by executing the below commands.
firewall-cmd --permanent --add-service=http firewall-cmd --reload
SELinux
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.

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=0
cgi.fix_pathinfo=0
Edit /etc/php-fpm.d/www.conf file.
vi /etc/php-fpm.d/www.conf
Make sure the following values are UN-commented.
[.More.] pm.min_spare_servers = 5 [.More.] pm.max_spare_servers = 35 [.More.]
Change Listen parameter.
FROM
listen = /run/php-fpm/www.sock
TO
listen = 127.0.0.1:9000
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. Edit the configuration.
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_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/web.itzgeek.local$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).
192.168.1.10 web.itzgeek.local
Open a web browser and enter your domain in the address bar.
The page will look like below.

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.

That’s All.