How To Install LEMP Stack On Ubuntu

install lemp stack on ubuntu server

As we know that LEMP stands for Linux, Nginx, MySQL & PHP. In this article, I have given the steps that you can follow to install the LEMP stack on ubuntu server.

#1. Installing Nginx on Ubuntu and allowing it through the firewall

We can use following steps:

Step 1: Update the packages first

Enter the command on the terminal:

      sudo apt update

After the command ask to your password … then you enter your password and then use this command is:

Step 2: Command for Installing Nginx:

      sudo apt install Nginx

Step 3: Allow Nginx through the firewall

      sudo ufw app list
      sudo ufw allow in ‘Nginx Full’

If we want to check status, then use this command:

Step 4: Check Firewall Status

      sudo ufw status

You can now go to the server URL (IP Address) and the Nginx default page will be displayed on the Screen.

Step 5: Check the default page on localhost

Go to the browser and type ‘http://your_domain_or_IP/localhost’ in your URL bar.

      localhost

#2. Installing MySQL on Ubuntu

We can run the command to install the MySQL is:

Step 1: Install MySQL

      sudo apt install mysql-server -y

After installation is completed, then you can run the command for entering the mysql is:

Step 2: Enter in MySQL

      sudo mysql

If you want to exit from the MySQL then enter the command is:

Step 3: Exit from MySQL

      exit

#3. Installing PHP on Ubuntu

We can run the command to install the PHP is:

Step 1: Install PHP

      sudo apt install php-fpm php-mysql

If we want to check the version of PHP, then we can enter the command is:

Step 2: Check the PHP version

      php -v

If you want to host a PHP website, you will have to copy your files to:

Step 3: Upload website files to following path

      cd /var/www/html

Step 4: Nginx website configuration file location

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

If we want to change any content from the any file, then we can use the:

Step 5: Updating Nginx website configuration file

      sudo nano filename

Installation is complete for the LEMP.

#4. Installing phpMyAdmin

      sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

#5. Configuring MySQL to use a password

Step 1: Check the MySQL user password status

If we set the password on MySQL then we can use this command:

      sudo mysql -u root -p

If we not set the password on MySQL then, we automatic enter the MySQL using this command:

      sudo mysql

After this command we create a user by using this command:

Step 2: Create a new user for MySQL database

      CREATE USER 'username'@'localhost' IDENTIFIED WITHcaching_sha2_password BY 'password123';

If our user create is successfully then, we can use this command for grant all privileges to the username:

Step 3: Grant access to database to this new user

      GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;

And all the process are completed then, we can exit with using by this command is:

Step 4: Exit MySQL

      exit

Step 5: Login with new username & password that you set

Go to the browser and type ‘http://your_domain_or_IP/phpmyadmin’ in your URL bar. You will see an option to log into your PHPMyAdmin console.

      localhost

#6. Create a symlink

      sudo ln -s /usr/share/phpmyadmin /var/www/html/phpMyAdmin

Check the installation:

      sudo service nginx restart

Note: If all the process are completed, and we get the issue for login page, then we can change the php version from the configuration file.

Share The Article

Share your thoughts

Leave a Reply

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