Steps of installing Apache, PHP, MySql & phpMyAdmin.

Step 1 : Updating the Package List

sudo apt-get update

Step 2 : Installing Apache

sudo apt-get install apache2

Step 3 : Checking Successful Installation of Apache

Check apache installed or not. Go to this URL http://your-ip-address, you will see the page like below image. For local server go to http://localhost

Step 4 : Installing MySql

sudo apt-get install mysql-server

It will ask the password for root user, also you need to confirm this password.

Step 5 : Checking Successful Installation of MySql

Type the following command to check MySQL installed successfully.

mysql -u root -p

Step 6 : Installing PHP with Commonly Used Extensions

sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-json php-mcrypt php-zip php-xml php-mbstring php-sqlite3

If you want to install a specific version of PHP then add version end of php.
Ex. sudo apt-get install php7.1

Install PHP extension
sudo apt-get install php-mbstring
Enable or Disable PHP extension
sudo phpdismod mbstring # disable mbstring extension
sudo phpenmod mbstring # enable mbstring extension again

Step 7 : Checking Successful Installation of PHP

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

This will create a phpinfo.php file in the /var/www/html/ directory.
Now go to http://localhost/phpinfo.php or http://your-ip-address/phpinfo.php

Step 8 : Installing phpMyAdmin

sudo apt-get install phpmyadmin

It will ask you to choose the type of web server, select apache2 then OK

Then it will ask for configure database for phpmyadmin with dbconfig-common, Choose Yes and press enter.

Then it be asked to enter the password of MySql root account. Enter the password which you typed while installing MySQL. Then will be asked to confirm this password.

Step 9 : Checking Successful Installation of phpMyAdmin

Visit the URL http://your-ip-addrss/phpmyadmin (or http://localhost/phpmyadmin for local server) in your browser. If phpMyAdmin is installed successfully, you should see the standard phpMyAdmin login page. Type in root as the username, and the MySql password you chose earlier to access the databases.

Step 10 : Enable Apache Rewrite Module

It’s very important to enable the Rewrite Module in Apache.

sudo a2enmod rewrite

Now restart the Apache server.

sudo service apache2 restart

Finish, We have successfully installed LAMP stack.

Thank You