By Bobby Iliev
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:
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.
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!
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.
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04
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:
- sudo phpenmod mbstring
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:
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:
- cd /tmp
- 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:
- sudo apt install unzip
After that unzip the archive:
- unzip phpMyAdmin-5.0.2-all-languages.zip
- mv phpMyAdmin-5.0.2-all-languages phpmyadmin
- 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 config.sample.inc.php
file:
- 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
:
- $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 auth_socket to mysql_native_password if you haven’t already done so. To do this, open up the MySQL prompt from your terminal:
- 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:
- 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:
- 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:
- 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:
- 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
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.
- 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:
- 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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.