Installing LEMP Stack on AlmaLinux

LEMP (Linux, Nginx, MySQL, PHP): An Overview

LEMP is an acronym representing the four essential components that constitute a web server environment. LEMP includes the following components:

  1. Linux (Operating System):
    • L stands for Linux, representing the Linux operating system. Linux is an open-source operating system with a variety of distribution options.
  2. Nginx (Web Server):
    • E represents Nginx, a high-performance, open-source web server, and reverse proxy server software. Nginx is known for its lightweight nature and is commonly used for serving dynamic content, static files, and acting as a reverse proxy.
  3. MySQL (Database Management System):
    • M stands for MySQL, representing the MySQL database management system. MySQL is an open-source relational database management system commonly used for data storage and management in web applications.
  4. PHP (Programming Language):
    • P represents PHP, a programming language designed specifically for web development. PHP is widely used for creating server-side applications and is popular for its ease of use in web development.

The LEMP stack is a popular combination, especially for running web applications. Nginx is known for its high performance and low memory consumption, MySQL for database management, and PHP for creating dynamic content. Linux serves as the operating system that brings these components together. The LEMP stack is often preferred for building scalable and fast web applications.

Installing LEMP Stack on AlmaLinux

You can follow the steps below to install the LEMP (Linux, Nginx, MySQL, PHP) stack on AlmaLinux. This example uses the Nginx web server, MySQL database management system, and PHP programming language.

Step 1: Update Repositories

sudo dnf update

Step 2: Install Nginx

sudo dnf install nginx

Step 3: Start Nginx Service

sudo systemctl start nginx

Step 4: Enable Nginx to Start on Boot

sudo systemctl enable nginx

Step 5: Update Firewall Settings (Optional, as per your preference)

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https 
sudo firewall-cmd --reload

Step 6: Install MySQL

sudo dnf install mariadb-server mariadb

Step 7: Start MySQL Service

sudo systemctl start mariadb

Step 8: Enable MySQL to Start on Boot

sudo systemctl enable mariadb

Step 9: Secure MySQL Installation

sudo mysql_secure_installation

Step 10: Install PHP

sudo dnf install php php-fpm php-mysqlnd

Step 11: Start PHP-FPM Service

sudo systemctl start php-fpm

Step 12: Enable PHP-FPM to Start on Boot

sudo systemctl enable php-fpm

Step 13: Update Nginx Configuration

Edit Nginx’s default configuration file:

sudo nano /etc/nginx/nginx.conf

Add or update the following lines:

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

Then, restart Nginx:

sudo systemctl restart nginx

Now, you have an LEMP stack on AlmaLinux. You can check if Nginx is running by visiting “http://your_server_ip” in your web browser. Additionally, you can create a simple PHP file to verify that PHP is working and can access the MySQL database.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.