Question

How to install manually phpMyAdmin on Ubuntu?

It is usually recommended to use distribution packages when possible - they usually provide integration to your distribution and you will automatically get security updates from your distribution.

You can find a collection of step by step tutorials on how to do that here:

https://www.digitalocean.com/community/tutorial_collections/how-to-install-and-secure-phpmyadmin-with-apache

However in some cases if you have a custom environment or if the distribution packages do not work for any reason, you might want to install phpMyAdmin manually.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
April 7, 2020
Accepted Answer

There are a few ways of installing phpMyAdmin as described in the official documentation here:

https://docs.phpmyadmin.net/en/latest/setup.html

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!

Prerequisites

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:

https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04

  • 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:

https://digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04

Step 1 - Install the additional PHP modules

Make sure that you have the additional PHP modules required by phpMyAdmin installed:

  1. sudo apt update
  2. 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:

  1. sudo phpenmod mbstring

Afterward, restart Apache for your changes to be recognized:

  1. 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:

https://www.phpmyadmin.net/files/

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:
  1. cd /tmp
  • Then download the zip file:
  1. wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.zip
  • Unzip the archive

Note: if you don’t have upzip already installed you can install it with:

  1. sudo apt install unzip

After that unzip the archive:

  1. unzip phpMyAdmin-5.0.2-all-languages.zip
  • Rename the folder
  1. mv phpMyAdmin-5.0.2-all-languages phpmyadmin
  • Move the phpMyAdmin folder to your document root:
  1. 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:

  1. cd /var/www/html/phpmyadmin

Then with your favorite text editor open the config.sample.inc.php file:

  1. 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 localhost:

  1. $cfg['Servers'][$i]['host'] = localhost

Finally, rename the config:

  1. 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 auth_socket to mysql_native_password if you haven’t already done so. To do this, open up the MySQL prompt from your terminal:

  1. sudo mysql

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:

  1. 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:

  1. FLUSH PRIVILEGES;

After that you should be able to visit http://your_domain_or_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:

  1. sudo mysql

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:

  1. 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:

  1. sudo nano /etc/apache2/sites-available/000-default.conf

Add an AllowOverride All directive within the <Directory /var/www/html/phpmyadmin> section of the configuration file, like this:

<Directory /var/www/html/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride All
</Directory>
    . . .

Now that you have enabled .htaccess use for your application, you need to create one to actually implement some security.

  1. sudo nano /var/www/html/phpmyadmin/.htaccess

Within this file, enter the following information:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user

You can now create this file and pass it an initial user with the htpasswd utility:

  1. 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.

Conclusion

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! Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more