How to Install phpMyAdmin on Ubuntu 18.04

 In Dedicated, VPS, Web

Requirements:

  • For the purposes of this tutorial, we will be using an Ubuntu 18.04 server.
  • You will also need a working LAMP or LEMP (Linux, Apache/Nginx, MySQL, PHP) stack.
  • Full SSH root access or a user with sudo privileges is also required.

Step 1: Connect to Your Server

Before we begin,  you need to connect to your server via SSH as the root user or any other user with sudo privileges.

To connect to your server as the root user, use the following command:

ssh root@IP_ADDRESS -p PORT_NUMBER

Make sure to replace IP_ADDRESS and PORT_NUMBER with your actual server IP address and SSH port number.

Once logged in, make sure that your server is up-to-date by running the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install phpMyAdmin

phpMyAdmin is already available in the default Ubuntu package repositories.

To install phpMyAdmin, along will all of the required dependencies, run the following command:

sudo apt install phpmyadmin

During the installation, you will be asked a couple of questions.

Choose apache2 as your web server:

Choose <Yes> to configure a database for phpMyAdmin with dbconfig-common:

Enter and confirm a MySQL application password for phpMyAdmin:

With this last step, the phpMyAdmin installation has been completed.

To access your phpMyAdmin, first restart your apache2 web server with:

systemctl restart apache2

and type http://yourIPaddress/phpmyadmin in your browser to access the login page:

Step 3: phpMyAdmin Login

To manage your databases using phpMyAdmin, you will need to either log in as the MySQL root user or as another MySQL user account with administrative privileges. We will show you how to log in using both of these methods.

Log in as root

By default, the root user is set to use the auth_socket plugin in order to authenticate to your MySQL database server. If you want to be able to authenticate as the root user in your phpMyAdmin, you will have to change the authentication method from auth_socket to mysql_native_password.

To do this, connect to your server via SSH, and then log in to your MySQL database server by typing the following command:

sudo mysql

This will take you to the MySQL shell as the MySQL root user. To check the authentication method of all of your users, you can execute the following:

SELECT user,plugin FROM mysql.user;

You will get the following output on your screen:

+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
| mysql.session    | mysql_native_password |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
| phpmyadmin       | mysql_native_password |
+------------------+-----------------------+

In order to change the authentication plugin from auth_socket to mysql_native_password for your root user, you will need to run the following:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'STRONG_PASSWORD';

Make sure that you replace the STRONG_PASSWORD part with an actual strong password that you would like to use for your MySQL root user.

After this is done, you will need to flush all privileges in order for the changes to take effect:

FLUSH PRIVILEGES;

You can then run the same command again to check if the authentication method has been successfully updated:

SELECT user,plugin FROM mysql.user;

Output:

+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| root             | mysql_native_password |
| mysql.session    | mysql_native_password |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
| phpmyadmin       | mysql_native_password |
+------------------+-----------------------+

To disconnect from the MySQL database server, you can type:

exit;

You can now use your MySQL user to log in to your phpMyAdmin and manage your databases.

Create a new admin user

Another option is to create a new MySQL user with administrative privileges. We will show you how to create a new user called “admin” which you can use to log in to your phpMyAdmin.

To create this new user, once again log in to your MySQL database server with:

sudo mysql

And run the following command:

CREATE USER 'admin'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';

Again, make sure you set a strong password for your user. Next, set the appropriate privileges by running:

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;

To exit the MySQL database server, type:

exit;

Step 4: Conclusion

Congratulations! If you have made it to this step, you have successfully installed phpMyAdmin on your Ubuntu 18.04 VPS. You will be able to log in at http://yourIPaddress/phpmyadmin as the root user or as another administration user, depending on which of the two methods you decided to set up during the tutorial. Upon successful authentication, you will be taken to the main phpMyAdmin management page, as shown in the screenshot below, from which you can start working with your databases.

 

Recommended Posts

Start typing and press Enter to search