Loading...

How to Install LEMP Stack (Linux, Nginx, MySQL, PHP) on Ubuntu 20.04

Simple.Predictable.Scalable

Easily deploy your favorite applications in seconds at an unbeatable price for your next projects.

LEMP Stack Installation

LEMP stands for Linux, Nginx, MySQL, and PHP. It is a popular software stack used for hosting dynamic websites and applications. In this tutorial, we will guide you through the process of installing the LEMP stack on Ubuntu 20.04.

Step 1: Update the System

Before installing any packages, it is recommended to update the system with the latest patches and upgrades. Open the terminal and run the following command:

        
sudo apt update
sudo apt upgrade
        
    

Step 2: Install Nginx

Nginx is a high-performance web server that will serve as the front-end for our LEMP stack. To install Nginx, use the following command:

        
sudo apt install nginx
        
    

Step 3: Install MySQL

MySQL is a popular open-source database management system. To install MySQL, run the following command:

        
sudo apt install mysql-server
        
    

During the installation, you will be prompted to set a password for the MySQL root user. Make sure to choose a strong password and remember it for future use.

Step 4: Install PHP

PHP is a server-side scripting language used for creating dynamic web pages. To install PHP and its necessary extensions, use the following command:

        
sudo apt install php-fpm php-mysql
        
    

Step 5: Configure Nginx

Next, we need to configure Nginx to work with PHP. Open the default Nginx configuration file in a text editor:

        
sudo nano /etc/nginx/sites-available/default
        
    

Inside the server block, locate the location directive that begins with index index.html; and modify it to include index.php:

        
location / {
    index index.php index.html;
}

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

Save and close the file. Then, test the Nginx configuration for any syntax errors:

        
sudo nginx -t
        
    

If there are no errors, restart Nginx to apply the changes:

        
sudo systemctl restart nginx
        
    

Step 6: Test the LEMP Stack

Finally, let's test if our LEMP stack is working correctly. Create a new PHP file in the default document root directory:

        
sudo nano /var/www/html/info.php
        
    

Add the following line to the file:

        

        
    

Save and close the file. Now, you can access the file in your web browser by navigating to "http://your-server-ip/info.php". If everything is set up correctly, you should see the PHP information page.

Congratulations! You have successfully installed the LEMP stack on Ubuntu 20.04. You can now start developing and hosting your dynamic websites and applications.

Installing LEMP Stack
Linux
Nginx
MySQL
PHP
Ubuntu 20.04

Why Customers Love Us

What our customers say about us

Ready To Get Started For Free?

Create your free account today.