How to Install Lamp phpMyAdmin on Amazon AWS EC2 Linux 2 Ubuntu

Installing and configuring LAMP stack with phpmyadmin in an Amazon AWS EC2 linux 2 instance is very easy, for this you simply connect to the AWS EC2 Linux 2 instance through an ssh terminal, and then, type some apt or yum commands on the ssh terminal window, press enter, these commands will install lamp stack with phpmyadmin on amazon aws linux 2 with ubuntu 22.04|20.04.

How to Install Lamp phpMyAdmin on Amazon AWS EC2 Linux 2 Ubuntu 18.04|20.04|22.04

Here are steps to install lamp(Linux, apache 2, PHP and MySQL) and PHPMyAdmin on amazon aws ec2 linux 2 ubuntu 18.0|20.0|22.04:

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 – Connect to AWS EC2 Instance via 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.0|20.0|22.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:

install apache 2 web server on amazon ec2
install apache 2 web server on amazon ec2

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

Here are steps to install php on amazon aws linux 2 with ubuntu 22.04|20.04:

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 and Configure phpMyAdmin on AWS EC Linux 2 Server

Here are steps to install phpmyadmin on Amazon AWS Linux 2 with Ubuntu 22.04|20.04:

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:

Conclusion

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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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