Install phpMyAdmin host on Amazon EC2 Example




Install phpMyAdmin host on Amazon EC2 Example

Hi Guys,

Here, I will show you how to works Install phpMyAdmin host on Amazon EC2 Example. I explained simply about Tutorial: Install a LAMP web server on the Amazon Linux EC2. This article goes in detailed on Follow the following easy steps to install a LAMP server. We will use Securing your phpMyAdmin installation on your EC2. Let's get started with Connect to phpMyAdmin On Amazon EC2.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Step 1: Update System Packages and Install MySQL

Run install update for your server system packages

sudo apt update

Now, install MySQL using the below command to install the latest MySQL.

sudo apt-get install mysql-server -y

After successful installation of mysql-server, we can check the MySQL version by using this command-


mysql --version

Step 2: Configure MySQL Installation

To configure the installation of MySQL, run the security script with sudo to run as the root user- the super privileged user.

Run the below command-


sudo mysql_secure_installation

When we install MySQL for the first time, we will be prompted to create a new password.

If you are getting an error while setting up the password, check the temporary password in the log file.

Use the below command to get a temporary password.


cat /var/log/mysqld.log

We can find something like this:

Configure MySQL Installation

Step 3: Login into MySQL and Create a User

Use the below command to login into MySQL:

sudo mysql

The command will log in to MySQL using the root user. Once you are logged in, create a user in the MySQL database using these commands:

use mysql;

CREATE USER 'username'@'host' IDENTIFIED WITH mysql_native_password BY 'password';

Step 4: Grant Access Privileges to User

Now, to grant access privileges to this newly created user, use this command:

GRANT ALL PRIVILEGES ON *.* TO 'username'@'host';

Once this is done, run this command,


Step 5: Connect User with MySQL

Now you can use this user to connect with MySQL like this:

mysql -u user -p

Once prompted for a password, provide the password, and you will be connected.

Trick: If you want to store passwords for that user, so prompting will not annoy us, do these things.

Create .my.cnf file inside /home/Ubuntu path

Write this command:

sudo nano .my.cnf

Write these lines in that file and save.




Now, whenever you want to connect, you can use this .my.cnf file like this, and no need to provide a password.

mysql --defaults-file=/home/ubuntu/.my.cnf -u username

This file is generally needed when running the CI/CD pipeline and connecting to another server’s MySQL server.

Step 6: Restart MySQL Service

To affect these changes, restart the MySQL service by following commands:

to check the status of MySQL service:

systemctl status mysql.service

Now, if it is in “Running” mode, then restart it using the below command:

sudo service mysql restart

This will restart the service and will reflect our changes.

Now, your MySQL has been set up in your Ubuntu Ec2 Instance.