Menu
User

DropVPS Team

Writer: Cooper Reagan

How to Install LEMP Stack on Red Hat (RHEL 9/10)

How to Install LEMP Stack on Red Hat (RHEL 9/10)

Publication Date

09/21/2025

Category

Articles

Reading Time

2 Min

Table of Contents

The LEMP stack (Linux, Nginx, MariaDB, and PHP) is a modern solution for hosting dynamic websites and applications. On Red Hat Enterprise Linux, you can install it using the built-in dnf package manager.

Step 1: Update Your System

Keeping the system updated ensures better stability:

sudo dnf update -y

Step 2: Install Nginx

Nginx is available in RHEL repositories:

sudo dnf install nginx -y

Start and enable the service:

sudo systemctl enable nginx
sudo systemctl start nginx

Check it in a browser:

http://your_server_ip

Step 3: Install MariaDB

MariaDB is the database server used in the LEMP stack.

sudo dnf install mariadb-server -y

Start and secure it:

sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation

Step 4: Install PHP and Extensions

Install PHP with required modules for Nginx:

sudo dnf install php php-fpm php-mysqlnd -y

Enable and start PHP-FPM:

sudo systemctl enable php-fpm
sudo systemctl start php-fpm

Step 5: Configure Nginx for PHP

Create a new server block:

sudo nano /etc/nginx/conf.d/myapp.conf

Paste this configuration:

server {
    listen 80;
    server_name myapp.local;

    root /usr/share/nginx/html/myapp;
    index index.php index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Test and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Step 6: Test PHP

Create a test file:

echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/myapp/index.php

Open in a browser:

http://your_server_ip/index.php

If the PHP info page appears, everything is working.

The LEMP stack is now fully installed and configured on Red Hat Enterprise Linux. Your system is ready to run PHP-based applications with Nginx and MariaDB.
Linux VPS
U
Loading...

Related Posts