How to install and use phpMyAdmin on an Ubuntu cloud server?

18-02-2024 02:24:26

phpMyAdmin is an open-source browser-based MySQL database management tool. It allows for easy management of databases, data tables, indexes, users, permissions, and more without the need to learn command-line interfaces. phpMyAdmin also supports various import and export formats such as csv and sql, making it one of the most popular database management software tools available. This guide is based on an Ubuntu 20.04 cloud server and outlines the steps for installing and using phpMyAdmin.

Installing phpMyAdmin

Update Ubuntu to the latest status.

$ sudo apt update -y

Install necessary PHP extensions.

$ sudo apt install -y php-json php-mbstring php-zip php-gd php-curl

Install the phpMyAdmin software package

$ sudo apt install -y phpmyadmin

When prompted to select a web server, choose apache2 as shown in the screenshot.

When asked about setting up the phpMyAdmin database, select "Yes" and press Enter to proceed.

Enter a complex password for the phpMyAdmin database, press Tab, and then Enter to move to the next step.

Re-enter the same password, press Tab, and then Enter to proceed.

Enable the phpMyAdmin configuration file just created using the a2enconf command and restart the Apache server.

$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
$ sudo a2enconf phpmyadmin.conf
$ sudo systemctl restart apache2

At this point, phpMyAdmin has been successfully installed. Next, we will create a sample database to demonstrate logging in and managing with phpMyAdmin.

Creating a Database

Log in to the MySQL database via the command line, enter the root user password, and press Enter to proceed.

$ sudo mysql -u root -p

Create a sample database and user, granting the user necessary permissions to the database.

mysql> CREATE database sample_db;
mysql> CREATE USER 'test_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'EXAMPLE_PASSWORD';
mysql> GRANT ALL PRIVILEGES ON sample_db.* TO 'test_user'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> QUIT;

Access the phpMyAdmin management address: http://192.0.2.1/phpmyadmin, and enter the username and password created earlier.

Upon successful login, the phpMyAdmin management dashboard will appear like the example shown, with the sample_db database visible on the left side.

With these steps completed, phpMyAdmin has been successfully installed on this Ubuntu 20.04 cloud server.