Table of Contents
What you will read?
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.
Need a Linux Server for This?
Run Debian, Ubuntu, or any Linux distro on DropVPS โ fast NVMe SSD, full root access, and 24/7 support. Perfect for everything you just read.
- Full Root Access
- Debian & Ubuntu Ready
- 99.99% Uptime
- 24/7 Support
No commitment ยท Cancel anytime
