Tuesday, April 30, 2024

Install LEMP Stack on Ubuntu

Assalamu Alaikum.
Welcome to Uddoyon, in this article we try to know about LEMP (Linux, nginX, MySQL, and PHP) Installation on Ubuntu 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 Ubuntu server. By the end of this tutorial, you’ll have a fully operational web server ready to host your web projects.

- Advertisement -

Prerequisites:
* A fresh Ubuntu installation (tested on Ubuntu 22.04 LTS).
* Access to a terminal with sudo privileges.

Step 1 – Update System Packages:
Begin by updating and upgrading your system’s package repository:

- Advertisement -
sudo apt update
sudo apt upgrade

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

sudo apt install nginx

Step 3 – Install MySQL Server:
Install MySQL a robust and widely used relational database management system:

- Advertisement -
sudo apt install mysql-server

During installation, you’ll be prompted to set a root password for MySQL.

Step 4 – Install PHP and Essential Extensions:
PHP is a server-side scripting language that enables dynamic content generation. Install it along with essential extensions:

sudo apt install php-fpm php-mysql

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

server {
    listen 80;
    server_name your_domain.com www.your_domain.com;

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

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Enable the configuration and reload Nginx:

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 6 – Create Web Root Directory and Test PHP:
Create the directory for your website files and create a PHP test file to ensure PHP-FPM is working:

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

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

Step 7 – Secure MySQL Installation:
Run the MySQL security script to enhance the security of your MySQL installation:

sudo mysql_secure_installation

Final Words:
Congratulations! You have successfully installed and configured a LEMP stack on your Ubuntu server. This powerful combination of Linux, Nginx, MySQL, and PHP forms a solid foundation for hosting and deploying dynamic web applications. You are now equipped to develop and serve 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 !!