This guide will walk you through the steps to deploy a LEMP stack with Let’s Encrypt on a Red Hat server.
Step 1: Update System Packages
sudo yum update -yStep 2: Install Nginx
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginxVerify Nginx is running:
sudo systemctl status nginxStep 3: Install MySQL
sudo yum install @mysql -y
sudo systemctl start mysqld
sudo systemctl enable mysqldSecure MySQL installation:
sudo mysql_secure_installationStep 4: Install PHP
sudo yum install php php-fpm php-mysqlnd -y
sudo systemctl start php-fpm
sudo systemctl enable php-fpmEdit PHP-FPM configuration to work with Nginx:
sudo vim /etc/php-fpm.d/www.confSet the following:
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginxRestart PHP-FPM:
sudo systemctl restart php-fpmStep 5: Configure Nginx
Create a new Nginx server block:
sudo vim /etc/nginx/conf.d/example.com.confAdd the following configuration:
server {
listen 80;
server_name example.com www.example.com;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}Test Nginx configuration:
sudo nginx -tRestart Nginx:
sudo systemctl restart nginxStep 6: Install Certbot
sudo yum install certbot python3-certbot-nginx -yStep 7: Obtain SSL Certificate
sudo certbot --nginx -d example.com -d www.example.comFollow the prompts to complete the certificate installation.
Step 8: Configure Firewall
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reloadStep 9: Verify HTTPS
Open your browser and visit https://example.com to ensure everything is working correctly.
Conclusion
You have successfully deployed a LEMP stack with Let’s Encrypt on your Red Hat server.

