How to Install LAMP on aws EC2 with Ubuntu 18.04
aws lamp The following procedures help you install an Apache web server with PHP and MySQL support on your Amazon Linux instance (sometimes called a LAMP web server or LAMP stack). You can use this server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.
1. Connecting to Instance
Step 1 – Installing Apache
aws lamp Before installing Apache, you need to update the package list for upgrades and new packages.
sudo apt-get update
Now Apache can be installed.
sudo apt-get install apache2
Step 2 – Installing MySql
1. Install MySql Server
sudo apt-get install mysql-server
2. After MySql has been installed, you will need to set the root password of the database and secure it using the following command :
3. You will be presented a screen where MySQL asks whether you would like to activate the VALIDATE PASSWORD PLUGIN. For now, keeping things simple, type no.
4. the next type the root password of your choice. Confirm it again.
5. In the next screen MySql will ask whether to remove anonymous users. Type yes
6. Disallow root login remotely? Type No
7. Remove test database and access to it? Type Yes
8. Reload privilege tables now? Type Yes
9. After the password has been set you can check the whether MySQL is working correctly by logging into the database with the command :
sudo mysql -u root -p
Password is the same that was set in the previous step.
If everything went smoothly, you will be welcomed by the mysql prompt.
10. Type exit to get out of MySql
Step 3 – Installing PHP with Common Extensions
1. Now install PHP and commonly used PHP extensions by using the following command :
Now install different supported versions of PHP as follows.
For Apache Web Server
<!--for 5.6--> sudo apt install php5.6 <!--for 7.0--> sudo apt install php7.0 <!--for 7.1--> sudo apt install php7.1 <!--for 7.2--> sudo apt install php7.2 <!--for 7.3--> sudo apt install php7.3
For Nginx Web Server
<!--for 5.6--> sudo apt install php5.6-fpm <!--for 7.0--> sudo apt install php7.0-fpm <!--for 7.1--> sudo apt install php7.1-fpm <!--for 7.2--> sudo apt install php7.2-fpm <!--for 7.3--> sudo apt install php7.3-fpm
2. Set Default PHP Version in Ubuntu
Set Default PHP Version 5.6
sudo update-alternatives --set php /usr/bin/php5.6
Set Default PHP Version 7.0
sudo update-alternatives --set php /usr/bin/php7.0
Set Default PHP Version 7.1
sudo update-alternatives --set php /usr/bin/php7.1
3. After switching from one version to another, you can find your PHP configuration file, by running the command below.
------------ FOR PHP 5.6 ------------ SUDO UPDATE-ALTERNATIVES --SET PHP /USR/BIN/PHP5.6 $ PHP -I | GREP "LOADED CONFIGURATION FILE" ------------ FOR PHP 7.0 ------------ SUDO UPDATE-ALTERNATIVES --SET PHP /USR/BIN/PHP7.0 $ PHP -I | GREP "LOADED CONFIGURATION FILE" ------------ FOR PHP 7.1 ------------ SUDO UPDATE-ALTERNATIVES --SET PHP /USR/BIN/PHP7.1 $ PHP -I | GREP "LOADED CONFIGURATION FILE" ------------ FOR PHP 7.2 ------------ SUDO UPDATE-ALTERNATIVES --SET PHP /USR/BIN/PHP7.2 $ PHP -I | GREP "LOADED CONFIGURATION FILE" ------------ FOR PHP 7.3 ------------ SUDO UPDATE-ALTERNATIVES --SET PHP /USR/BIN/PHP7.3 $ PHP -I | GREP "LOADED CONFIGURATION FILE"
4. After PHP has been installed, restart Apache.
sudo service apache2 restart
Step 4. Installing phpMyAdmin on aws lamp
To install phpMyAdmin execute the following command :
sudo apt install phpmyadmin
Following which you will be presented with options to configure phpmyadmin for the server:
1. The first option is to select the proper web server. It is important to note here that although apache2 is highlighted it hasn’t been selected.
Select apache2 by pressing the space-bar. Then press Tab key that takes us to the Ok button. Now press enter.
2. Next option is to configure the database for phpmyadmin with dbconfig-common. Select the Yes option here.
3. Then password is asked for login to phpmyadmin. By default the username is phpmyadmin. You are now setting the password for this user (this is different from the roor user).
Press Tab key to go the Ok button.
4. Now phpMyAdmin can be accessed from the browser by navigating to
Enter the login credentials with user phpmyadmin and the associated password.
Step 5. Allowing Mysql Root Login through phpMyAdmin
This step is optional. By default you cannot login as root user through phpMyAdmin. To do this perform the below steps :
1. Login to MySql root.
sudo mysql -u root -p
2. Enter the query to change root login authentication from socket to password.
ALTER USER 'ROOT'@'LOCALHOST' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY 'PASSWORD';
Replace password by the root password you entered while installing MySql.
3. Enter the query to put the changes into effect.
Now you can login as root from phpMyAdmin.