Install lamp stack with phpmyadmin on ubuntu amazon ec2. Here, we will show you step by step on how to install lamp stack with phpmyadmin on ubuntu 18.04 ec2 aws.
How to Install LAMP Stack, PHPmyadmin on Ubuntu 18.04 AWS EC2
Follow the following easy steps to install lamp(Linux, apache 2, PHP and MySQL) and PHPMyAdmin on ubuntu 18.04 amazon(aws) ec2:
- Step 1: Launch New AWS ec2 Instance
- Step 2: Connecting your AWS EC2 Instance from SSH
- Step 3: Install Apache 2 on ubuntu 18.04
- Step 4: Install MySql
- Step 5: Install PHP 7.3
- Step 6: Install, Configure and Access phpMyAdmin
Step 1 – Launch New AWS ec2 Instance
First of all, you need to launch aws ec2 instance. If you have already launch new ec2 instance, so you can move next step. Otherwise you need to read this tutorial “how to launch ec2 instance in aws step by step“ for launch aws ec2 instance.
Step 2 – Connecting your AWS EC2 Instance from SSH
In this step, you need to connect your aws ec2 instance from ssh terminal. If you are new to connect aws ec2 instance with windows, ubuntu and mac system. So you can read this tutorial “How to Connect to ec2 Instance From Putty and SSH Terminal” to connect your ec2 instance from ssh.
Step 3 – Install Apache 2 on ubuntu 18.04
3.1 – Update Ubuntu System Repositories
sudo apt update
3.2 – Update Ubuntu System Repositories
sudo apt install apache2
3.3 – List the UFW application profiles
sudo apt install apache2
3.4 – sudo ufw allow ‘Apache Full’
sudo ufw allow 'Apache Full'
3.5 – Verify that the Apache service is running
sudo systemctl status apache2
3.6 – Open Browser and type EC2 intance IP
Finally, open your browser and type your AWS ec2 instance IP address. And, it will be looks like the Apache 2 page in the following picture:
Step 4 – Install MySQL
4.1 – Installing MySQL server
Now, open your ssh terminal and type the following command to install MySql Server:
sudo apt-get install mysql-server
4.2 – Securing MySQL server in Apache aws ec2
Then, secure MySql server by using the following command. So, you will need to set the root password of the database and secure it using the following command :
sudo mysql_secure_installation
When you run this command. Then the questions given below in the prompt will appear:
- You will be presented with a screen where MySQL asks whether you would like to activate the VALIDATE PASSWORD PLUGIN. For now, keeping things simple, type no.
- In the next type the root password of your choice. Confirm it again.
- In the next screen MySql will ask whether to remove anonymous users. Type yes
- Disallow root login remotely? Type No
- Remove test database and access to it? Type Yes
- Reload privilege tables now? Type Yes
- 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
The above command will ask for the password. Password is the same that was set in the previous step.
Now, Type exit on ssh terminal to get out of MySql:
exit
Step 5 – Install PHP 7.3
5.1 – Install PHP and Common Extensions
Now, install PHP with it’s common extensions. So open your ssh terminal and type the following command:
sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip php-mbstring
5.2 – Edit dir.conf File
After successfully installed PHP on ubuntu amazon ec2 instance. Now, you need to configure dir.conf
file by using the following sudo nano command:
sudo nano /etc/apache2/mods-enabled/dir.conf
It will look like this:
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
Move the PHP index file to the first position after the DirectoryIndex
specification, like this:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Step 6 – Install, Configure and Access phpMyAdmin
6.1 – Installing phpmyadmin on amazon ec2 ubuntu
Open your ssh terminal and type the following command to install PHPMyAdmin on ubuntu amazon ec2 web server:
sudo apt install phpmyadmin
When you run this command. Then the selective option available for you on the prompt look like folloiwng:
When the first option is appear, you need to select apache2. Now it hasn’t been selected.
Use space bar to select apache2 web server. Then press Tab key that takes us to the Ok button. After that, press enter.
The next option is to configure the database for PHPMyAdmin with dbconfig-common. Select the Yes option here.
After that, password configuration is appear on your terminal screen. And it is asked for login to phpmyadmin. So, you can set your phpmyadmin access password here:
6.2 – Configure phpmyadmin in ubuntu ec2
Open again your ssh terminal and run the following command to configure phpmyadmin in apache2.conf file:
sudo nano /etc/apache2/apache2.conf
After that, add the following line into apache2.conf file and save it:
Include /etc/phpmyadmin/apache.conf
6.3 – Enable MySQL root Login for phpmyadmin ubuntu aws
Note that, By default root cannot login as root user through phpMyAdmin.
So, open your ssh terminal and type the following command to enable/allow mysql root login access for phpmyadmin on ubuntu aws web server:
sudo mysql -u root -p
Then type this following query:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Note that, Replace password by the root password you entered while installing MySql.
After that type following query to changes into effect:
FLUSH PRIVILEGES;
6.4 – Restart Apache Web Server
After successfully installed PHP MySQL and configure these on ubuntu amazon ec2 instance.
Finally, You need to restart Apache 2 server by using the following command:
sudo service apache2 restart
6.5 – Access phpmyadmin Amazon ec2
Finally, you can login as root from phpMyAdmin. So, open your browser and type the below url with your ec2 server ip:
http://[SERVER_PUBLIC_IP]/phpmyadmin
Then you will look like on your browser:
Finally, you have installed lamp (Linux, Apache 2, PHP, and MySQL), PHPMyAdmin on amazon(AWS) ec2 ubuntu. As well as secured MySQL database with a password.
Recommended Tutorials