Saturday, July 13, 2024

Install LEMP Stack on CentOS

Assalamu Alaikum.
Welcome to Uddoyon, in this article we try to know about LEMP (Linux, nginX, MySQL, and PHP) Installation on CentOS System so keep reading…

The LEMP stack, composed of Linux, Nginx, MySQL and PHP. LEMP is a popular web server environment that powers countless websites and applications. In this article we will walk you through the process of setting up a LEMP stack on an CentOS Server. By the end of this tutorial, you’ll have a fully operational web server ready to host your web projects.

- Advertisement -

* A fresh CentOS installation (tested on CentOS 8).
* Access to a terminal with sudo privileges.

Step 1 – Update System Packages:
Initiate by updating and upgrading the system’s package repositories:

- Advertisement -
sudo dnf update
sudo dnf upgrade

Step 2 – Install Nginx:
Nginx will serve as the lightweight and high-performance web server for our LEMP stack:

sudo dnf install nginx

Step 3 – Install MySQL Server:
Install MySQL, the versatile relational database management system:

- Advertisement -
sudo dnf install mysql-server

Follow the prompts to secure your MySQL installation by setting a root password.

Step 4 – Install PHP and Necessary Extensions:
PHP, the scripting language for dynamic content, and essential extensions should be installed:

sudo dnf install php-fpm php-mysqlnd

Step 5 – Configure Nginx for PHP:
Create a new server block configuration for your web application in “/etc/nginx/conf.d/your_domain.conf” (replace your_domain with your actual domain or project name):

server {
    listen 80;

    root /var/www/your_domain;
    index index.php index.html;

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

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;

    location ~ /\.ht {
        deny all;

Reload Nginx to apply the changes:

sudo systemctl reload nginx

Step 6 – Create Web Root Directory and Test PHP:
Create the directory for your website files and test PHP-FPM with a PHP info file:

sudo mkdir -p /var/www/your_domain
sudo chown -R nginx:nginx /var/www/your_domain
echo "<?php phpinfo(); ?>" | sudo tee /var/www/your_domain/info.php

Access the PHP test page by visiting http://your_domain/info.php in your browser.

Step 7 – Secure MySQL Installation:
Enhance MySQL security by running the security script:

sudo mysql_secure_installation

You’ve successfully installed and configured a LEMP stack on your CentOS server. The combination of Linux, Nginx, MySQL, and PHP provides a solid foundation for hosting and serving dynamic web applications. You’re now well-equipped to develop and deploy your web projects efficiently and securely.

Thanks for Reading, stay with us to know more things as like this.

- Advertisement -
- Advertisement -
Related Articles
- Advertisement -

Popular Articles

- Advertisement -
error: Content is protected !!