If you’re working with MySQL or MariaDB on Ubuntu, managing databases purely from the command line can quickly feel overwhelming. That’s where phpMyAdmin comes in. PHPMyAdmin is a web-based application that provides a Graphical User Interface (GUI) for MySQL database administration, making everyday tasks much simpler and faster.
It supports multiple MySQL servers and serves as an easy, user-friendly alternative to the MySQL command-line client, allowing you to create databases, manage users, run queries, and handle backups directly from your browser.
In this guide on How to Install PHPMyAdmin on Ubuntu, we’ll walk you through the complete installation and configuration process step by step for Ubuntu 18.04, 16.04, and 14.04. Whether you’re setting up a local development environment or managing a live production server, this tutorial will help you get phpMyAdmin installed, secured, and running smoothly in no time.
Prerequisites
Before you get started with this guide, make sure you’ve completed a few basic setup steps.
This tutorial assumes that you already have a LAMP stack (Linux, Apache, MySQL, and PHP) or a LEMP stack (Linux, Nginx, MySQL, and PHP) properly installed and configured on your Ubuntu 14.04 server. phpMyAdmin requires a working web server, database server, and PHP to function correctly.
If you haven’t set up LAMP or LEMP yet, don’t worry—you can follow the relevant guides below to get your server ready before continuing with the phpMyAdmin installation.
Now, check hostname and Fully Qualified Domain Name (FQDN).
hostname
hostname -f
hostname: This command shows your hostname.Hostname -f: This command shows your fully qualified domain name (FQDN).
How to Install PHPMyAdmin on Ubuntu
Update your system
sudo apt-get update && sudo apt-get upgrade -y
Install the mcrypt PHP module
sudo apt-get install mcrypt
Now restart your Apache Server by executing the following command:
sudo service apache2 restart
To get started, install phpMyAdmin from the default repositories of Ubuntu. To pull down the required files and proceed with the installation, the apt packaging system can be used:
sudo apt-get install phpmyadmin
You will be asked for the server for which you want phpMyAdmin automatically configure. Select the installed web server on your Ubuntu. If you have multiple web server installed, you can choose the best-suited web server as per your need and deployment. After that, you can follow through the rest of the steps to set passwords.
Create a symbolic link from root to PHPMyAdmin directory for each virtual hosts to give access to your PHPMyAdmin installation:
cd /var/www/example.com/public_html
sudo ln -s /usr/share/phpmyadmin
Alternatively, you can do it by running a single line command as well. Both mean the same:
sudo ln -s /usr/share/phpmyadmin /var/www/example.com/public_html
It will create a symbolic link named PHPMyAdmin in the root document.
As we know that mcrypt is a PHP module on which phpMyAdmin relies on. So we need to enable the mcrypt by restarting the PHP processor using the command below.
sudo php5enmod mcrypt
sudo service php5-fpm restart
Now phpMyAdmin is operational. For phpMyAdmin interface access, enter the server’s IP address or domain name followed by /PHPMyAdmin, in a web browser:
http://server_domain_or_IP/phpmyadmin
Securing phpMyAdmin
1. .htaccess File
Now we need secure phpMyAdmin by using .htaccess file. This will allow specified IP addresses to access it. It can be done by creating a .htaccess file inside the PHPMyAdmin directory.
/var/www/example.com/public_html/phpmyadmin/.htaccess
order allow,deny allow from 12.34.56.78
2. Force SSL
You can use your phpMyAdmin to use SSL in phpMyAdmin configuration file, which is present inside /etc/phpmyadmin/config.inc.php directory. You can add the following line under the Server(s) configuration section:
$cfg['ForceSSL'] = 'true';
3. Changing the Application’s Access Location
Now, we need to rename the symbolic link to change the access location of the web application from where the graphical user interface (GUI) of PHPMyAdmin can be accessed.
To know what exactly we are doing, let’s navigate to the Nginx document root directory:
cd /var/www/example.com/public_html
ls -l
The output goes something like this:
total 188 -rw-r--r-- 1 www-data www-data 418 Apr 18 15:37 index.php -rw-r--r-- 1 www-data www-data 19935 Apr 18 15:37 license.txt lrwxrwxrwx 1 root root 18 Apr 6 15:37 phpmyadmin -> /usr/share/phpmyadmin
If we look at line 4, we can clearly identify that we have a symbolic link i.e, PHPMyAdmin in this directory. We can change this symbolic link to some other name or location that we would like to. This will change the access location of PHPMyAdmin. To do that let’s pick a new name for our symbolic link. Let’s call it “anonymous”. To create a symbolic link with this name, run the following command:
sudo mv phpmyadmin anonymous
Once you are done, run the following command:
ls -l
Now, you will notice that the symbolic link name has changed:
total 188 -rw-r--r-- 1 www-data www-data 418 Apr 18 15:40 index.php -rw-r--r-- 1 www-data www-data 19935 Apr 18 15:40 license.txt lrwxrwxrwx 1 root root 18 Apr 6 15:40 anonymous -> /usr/share/phpmyadmin
Now, if try to navigate to the previous phpMyAdmin directory location, you will get a 404 error:
http://server_domain_or_IP/phpmyadmin
However, your phpMyAdmin will be accessible at the new location:
http://server_domain_or_IP/anonymous
4. Web Server Authentication Gate Setup
Web server authentication gate is a feature that enables authentication. Prompt that a user would be required to pass even before seeing the phpMyAdmin login screen.
In most of the web servers, this capability is natively available which includes Nginx as well. We just require modifying the configuration file of the Nginx web server.
Before we do this, we need to create a password file that will store the web server authentication gate credentials. Nginx needs that passwords in encrypted form using the crypt() function. OpenSSL suite, which is already installed on your server, includes this functionality.
So, to create an encrypted password, run the following command:
openssl passwd
Now, you will be asked to enter the password that you need to confirm to use. Once you are done, you will be displayed an encrypted version of the password that will look like something this:
zV.cjsFPfRQ6g
Copy this encrypted password in a notepad. Later, we would require this password while creating web server authentication gate credential file.
Now, create web server authentication gate credential file. We will call this file pma_pass and we need to save it inside the Nginx configuration directory:
sudo vim /etc/nginx/pma_pass
Now we need to specify the username and followed by a colon (:), followed by the encrypted version of the password that we generated during the encrypted password creation process using the openssl passwd.
Let’s say we have chosen a username “webmaster”, then it goes like this:
webmaster:zV.cjsFPfRQ6g
Save and close the file.
Now, we need to modify our Nginx configuration file.Open the Nginx configuration file for your website:
Open the Nginx configuration file for your website:
sudo vim /etc/nginx/sites-available/example.com
Within the server block, inside example.com file, add a new location. This will set the location for phpMyAdmin interface.
server {
. . .
location / {
try_files $uri $uri/ =404;
}
location /anonymous {
}
. . .
}
Within this block, set the value of a directive called auth_basic to an authentication message that the prompt will display.
In another directive called auth_basic_user_file, point web server to the authentication file that we created earlier.
After updating the configuration, the file should look like this:
server {
. . .
location / {
try_files $uri $uri/ =404;
}
location /anonymous {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
}
. . .
}
Now save and close the file.
Now check whether authentication gate is working or not. For that, we need to restart the web server:
sudo service nginx restart
Now, visit the phpMyAdmin location in your web browser. You are asked to enter the username and the password that you added earlier to the pma_pass file. Clear the browser cache and start a new session in case it does not ask for username and password.
Now enter the following web address in the browser by replacing the server_domain_or_IP with your IP address.
http://server_domain_or_IP/anonymous
Conclusion
That’s it! You are done installing and securing phpMyAdmin on Ubuntu.
You’ve now learned how to install PHPMyAdmin on Ubuntu 18.04, 16.04, and 14.04 and set it up to manage your MySQL or MariaDB databases with ease. By using phpMyAdmin’s web-based graphical interface, you can perform database administration tasks faster and more efficiently without relying entirely on the command line.
Whether you’re managing a development environment or a production server, phpMyAdmin simplifies everyday database operations such as creating databases, managing users, running queries, and taking backups.
For better security, always ensure your server is up to date and restrict access to phpMyAdmin using strong passwords or additional authentication methods. With the setup complete, you’re now ready to manage your databases confidently on Ubuntu.
You can also check out the official documentation for how to install PHPMyAdmin on Ubuntu.
Hope you will find this tutorial on how to install PHPMyAdmin on Ubuntu useful. I would like to hear your views in the comment section below.
How to Install PHPMyAdmin on Ubuntu
What is phpMyAdmin used for?
phpMyAdmin is a web-based tool used to manage MySQL and MariaDB databases. It allows you to create and delete databases, manage users and permissions, run SQL queries, import/export data, and perform backups using a graphical interface.
Is phpMyAdmin free to use?
Yes, phpMyAdmin is completely free and open-source software released under the GNU General Public License (GPL).
Can I install phpMyAdmin on any Ubuntu version?
phpMyAdmin can be installed on most Ubuntu versions, including 18.04, 16.04, and 14.04. However, older versions like Ubuntu 14.04 are end-of-life and should only be used in legacy environments.
Do I need a LAMP or LEMP stack to use phpMyAdmin?
Yes. phpMyAdmin requires a web server (Apache or Nginx), PHP, and a database server (MySQL or MariaDB). That’s why a LAMP or LEMP stack must be installed before setting up phpMyAdmin.
Is phpMyAdmin secure for production servers?
phpMyAdmin can be secure if properly configured. It’s recommended to protect it with strong passwords, restrict access using firewall rules or authentication, and keep both Ubuntu and phpMyAdmin updated.
How do I access phpMyAdmin after installation?
Once installed, you can usually access phpMyAdmin by visiting http://your-server-ip/phpmyadmin or http://your-domain/phpmyadmin in your web browser.
Can phpMyAdmin manage multiple databases or servers?
Yes, phpMyAdmin supports managing multiple databases and can connect to multiple MySQL or MariaDB servers from a single interface.
What should I do if phpMyAdmin shows a login error?
Login errors are often related to incorrect MySQL credentials or authentication configuration. Double-check your database username and password, and ensure MySQL is running properly on your server.

How To Install Nginx on Ubuntu Server: 4 Simple Steps