How To Install LAMP Stack On Ubuntu

In this article, we will install LAMP i.e. Linux, Apache, MySQL, and PHP on ubuntu server.

#1. Installing Apache and allowing it through the firewall

We can use following steps:

Step 1:

sudo apt update

After the command ask to your password … then you enter your password.

Step 2:

sudo apt install apache2

Let’s allow Apache through the firewall using the following command

Step 3:

sudo ufw allow in “Apache Full”

If we want to check status, then use this command

Step 4:

sudo ufw status

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

Step 5:

You can go to the Firewall.

Enter the URL is

localhost

#2. Installing MySQL on Ubuntu:

We can run the command to install the MySQL is:

We can use following steps:

Step 1:

       sudo apt install mysql-server -y

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

Step 2:

       sudo mysql

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

Step 3:

       exit

#3. Installing PHP on Ubuntu:

We can run the command to install the PHP is:

Step 1:

     sudo apt install php libapache2-mod-php php-mysql -y

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

Step 2:

     php -v

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

Step 3:

     sudo nano filename

Installation is complete for the LAMP.

#4. Installing phpMyAdmin

Step 1:

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

Configuring MySQL to use a password

Step 2:

     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 3:

 CREATE USER 'username'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password123';

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

Step 4:

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 5:

exit

Check the installation:

sudo service apache2 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 *