There are a few ways of installing phpMyAdmin as described in the official documentation here:
However I’ve been using another method which is a bit more convenient for some cases, so I’ve decided to put a short tutorial on how to do that!
Before you get started with this guide, you need to have some basic steps completed.
- First, we’ll assume that you are using a non-root user with sudo privileges, as described in steps 1-4 in the initial server setup:
- We’re also going to assume that you’ve completed a LAMP (Linux, Apache, MySQL, and PHP) installation on your Ubuntu 16.04 server. If this is not completed yet, you can follow this guide on installing a LAMP stack:
Step 1 - Install the additional PHP modules
Make sure that you have the additional PHP modules required by phpMyAdmin installed:
- sudo apt update
- sudo apt install php-mbstring php-gettext
Also, you need to do is explicitly enable the mbstring PHP extension, which you can do by typing:
Afterward, restart Apache for your changes to be recognized:
- sudo systemctl restart apache2
Step 2 - Download the source files
You can visit the following link and copy the link of the latest stable phpMyAdmin version:
As of the time of writing this post, the latest phpMyAdmin was 5.0.2. So in order to download the files, you need to run the following commands:
- First go to the /tmp directory:
- Then download the zip file:
- wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.zip
Note: if you don’t have
upzip already installed you can install it with:
After that unzip the archive:
- unzip phpMyAdmin-5.0.2-all-languages.zip
- mv phpMyAdmin-5.0.2-all-languages phpmyadmin
- Move the phpMyAdmin folder to your document root:
- sudo mv phpmyadmin /var/www/html
Note: change the
/var/www/html path in case that you are using a custom virtual host with a non-standard document root
Step 3 - Configure phpMyadmin
First you need to go to the
/var/www/html/phpmyadmin directory and then update your phpMyAdmin config:
- cd /var/www/html/phpmyadmin
Then with your favorite text editor open the
- sudo nano config.sample.inc.php
And then update the following line to the correct database host, as we are running MySQL on the same Droplet just put
- $cfg['Servers'][$i]['host'] = localhost
Finally, rename the config:
- sudo mv config.sample.inc.php config.inc.php
Finally, in order to log in to phpMyAdmin as your root MySQL user, you will need to switch its authentication method from authsocket to mysqlnative_password if you haven’t already done so. To do this, open up the MySQL prompt from your terminal:
To configure the root account to authenticate with a password, run the following ALTER USER command. Be sure to change password to a strong password of your choosing:
- ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect:
After that you should be able to visit http://yourdomainor_IP/phpmyadmin and login with your root user.
Alternatively, some may find that it better suits their workflow to connect to phpMyAdmin with a dedicated MySQL user rather than the root user. To do this, open up the MySQL shell once again:
From there, create a new user and give it a strong password:
CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';
Then, grant your new user appropriate privileges. For example, you could grant the user privileges to all tables within the database, as well as the power to add, change, and remove user privileges, with this command:
- GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;
After that, you would be able to use the new user to login via phpMyAdmin and manage your databases.
Step 4 - Securing your phpMyAdmin Instance
It is strongly recommended to configure .htaccess authentication in order to protect your phpMyAdmin instance from brute-force attacks and just as a second layer of security.
Edit the linked file that has been placed in your Apache configuration directory:
- sudo nano /etc/apache2/sites-available/000-default.conf
AllowOverride All directive within the
<Directory /var/www/html/phpmyadmin> section of the configuration file, like this:
. . .
Now that you have enabled .htaccess use for your application, you need to create one to actually implement some security.
- sudo nano /var/www/html/phpmyadmin/.htaccess
Within this file, enter the following information:
AuthName "Restricted Files"
You can now create this file and pass it an initial user with the
- sudo htpasswd -c /etc/apache2/.htpasswd username
Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured.
You have successfully manually installed phpMyAdmin and you should now have phpMyAdmin configured and ready to use on your Ubuntu server.
Hope that this helps!