How to Setup PHPMyAdmin in AWS EC2 With SSL

In this article, I will discuss how you can set up PHPMyAdmin in AWS EC2 With SSL. But before that let’s discuss what is PHPmyadmin and why we need that in AWS.

What is PHPmyAdmin

According to WiKi, phpMyAdmin is a free and open-source administration tool for MySQL and MariaDB. As a portable web application written primarily in PHP, it has become one of the most popular MySQL administration tools, especially for web hosting services.

So PhpMyAdmin is a script that runs on PHP / APache and displays a visual interface to manage your MySQL database server. Using the PhpMyAdmin Graphical user interface you can do all the tasks which a Database administrator needs to do to manage the MySQL server.

Why we need PhpMyAdmin in AWS EC2

AWS is a cloud computing platform that provides you with computing resources based on your requirement. Using that compute resources like EC2 instances, you can do anything you want. Then, if you decided to install MySQL on your EC2 instance then you need a tool to manage your Database server. The command-line tool is not suitable for all and it’s hard to work for Database administrators. That’s why people prefer to use PhpMyAdmin to maintain their database server. In the below section I will discuss how you can install PHPmyAdmin so that you can easily manage your database server.

How to Install

To install PHPMyAdmin, we need to do the following steps.

  • Install MySQL server
  • Install PHP and Apache
  • Download PHPmyadmin from official site
  • Extract the files and create config files.
  • Update the config file hostname

The first step is to update YUM packages. YUM (Yellowdog Updater Modified) is an open-source command-line as well as graphical-based package management tool for RPM (RedHat Package Manager) based Linux systems. It allows users and system administrators to easily install, update, remove, or search software packages on a system. So “sudo yum update -y” basically updates all packages to its latest version from a repository list which is managed by Amazon for Amazon Linux. This is always a good practice to run “yum update” first before you install any software.

sudo yum update -y 

Next, we need to install MySQL. The command to install MySQL server in Amazon Linux 2 is given below.

sudo yum install -y httpd mariadb-server 

Once we installed MySQL, then we need to install PHP and Apache. Amazon Linux supports different PHP versions like 7.2, 7.3, and many other 7.x series. So first we need to enable a version which we want to install using amazon-linux-extras.

sudo amazon-linux-extras enable php7.4 

After enabling the desired version, we will run the below command to install PHP, Apache, and required PHP extensions.

sudo yum install httpd php php-cli php-common php-mysqlnd -y

If you have come fur without any error, then you have successfully installed PHP, Apache, and MySQL on your EC2 instance. Next, we need to download PHPMyAdmin from the official site. At the moment when I am writing this article, the latest version of PHPMyAdmin was 4.9.7.

cd /var/www
sudo wget https://files.phpmyadmin.net/phpMyAdmin/4.9.7/phpMyAdmin-4.9.7-english.zip

After downloading the PHPMyAdmin in Zip format, let’s extract that by running the following command.

sudo unzip phpMyAdmin-4.9.7-english.zip

This will extract the PHPMyAdmin in a folder named “phpMyAdmin-4.9.7-english”. Rename the folder name to a more user-friendly like “pma”. Then create a virtual host based on my other article here.

So far we have installed Apache server and PHP 7.4. Next, we need to enable EPEL so that we can install Certbot. To enable EPEL please run the following commands.

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --enable epel

Once we install enabled EPEL, then we need to install Certbot. This is the tool that will fetch the SSL certificate from EEF and setup into our server.

sudo yum install certbot python2-certbot-apache 

sudo certbot --apache

Now reboot the apache server and enjoy PHPMyAdmin with SSL.

An interactive video based on this article is also added here, feel free to watch it if you are stuck in any situation.

These commands I have given works with Amazon Linux 2. If you use a different Linux flavor then please change the command accordingly.

Conclusion

PHPmyAdmin is one of the most popular 3rd party scripts to Manage the MySQL database servers. In this article, I have shown the ways to install it on your EC2 instance and enable SSL as well for security. Feel free to contact us at [email protected] if you have any queries which are not covered by this article.

Related Articles

Setup MySQL Server

Become fit by riding Bike

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply