How to Secure phpMyAdmin on Your VPS (or Remove It Safely)
If you run phpMyAdmin on a VPS, you should lock it down before you use it for real work. The tool ships with many LEMP and LAMP stacks, and it is convenient: you open a browser tab, log in, and manage databases with clicks instead of commands. The problem is the default setup. It lives at a well-known URL, it accepts the MySQL root login, and bots scan the internet for it around the clock. One weak password is all it takes.
You have two good options. Lock it down properly, or take it off the server and manage MySQL another way. This guide walks through the hardening steps first, then shows how to remove it safely if you decide you do not need it.
Why phpMyAdmin on a VPS Needs Attention
phpMyAdmin is not broken software. The risk comes from how it is usually installed: same URL on every server, root login allowed, no extra password, no IP check, and sometimes no HTTPS. Bots try paths like /phpmyadmin, /pma, and /mysql on millions of IPs every day. They do not need to know your domain. They only need one server with a guessable password.
A strong password helps, but it is one layer. If that layer fails, there is nothing between the attacker and your databases. That is why securing phpMyAdmin belongs on the same list as the first things to do after buying a VPS. If the server runs WordPress, the same thinking applies to the WordPress hardening steps for VPS owners: close the obvious doors first, then add layers.
How to Secure phpMyAdmin on Your VPS in 5 Steps
Work through these in order. Each step cuts the risk on its own, and together they make phpMyAdmin a hard target instead of an easy one.
Step 1: Change the Default URL
The default path is the first thing bots try. Move phpMyAdmin to a path nobody can guess. On Apache, change the Alias in the phpMyAdmin config:
Alias /db-admin-9x4 /usr/share/phpmyadmin
On Nginx, change the location block to match the new path, then reload the web server. Pick a random string, keep it private, and do not link to it from any public page.
Step 2: Add a Second Password Layer
Before anyone reaches the phpMyAdmin login, make the web server ask for a password of its own. On Apache this is a phpMyAdmin htaccess password layer, set with an .htaccess file and htpasswd. On Nginx the same idea is auth_basic:
location /db-admin-9x4 {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
Use a different password from your MySQL password. An attacker now has to beat two logins instead of one.
Step 3: Allow Only Your IP Address
A phpMyAdmin IP whitelist is the single most effective step on this list. If your IP never changes, allow only that address and block everyone else. In Nginx:
location /db-admin-9x4 {
allow 203.0.113.10;
deny all;
}
Replace the example IP with your own. Pair this with UFW firewall rules for a web server so only ports 80 and 443 stay open to the public, and MySQL port 3306 stays closed.
Step 4: Force HTTPS Only
Never log in to phpMyAdmin over plain HTTP. Anyone on the same network can read the password as it travels. Install a certificate and redirect all HTTP traffic to HTTPS. If you have not set this up yet, follow the guide to install a free Let’s Encrypt certificate on Nginx with Certbot, then confirm the phpMyAdmin URL loads with a padlock and no HTTP version works.
Step 5: Stop Using the MySQL Root Account
Create a separate MySQL user that only manages the databases it needs, and use that account in phpMyAdmin:
CREATE USER 'pma_admin'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON your_database.* TO 'pma_admin'@'localhost';
FLUSH PRIVILEGES;
Then block root login in phpMyAdmin by setting AllowRoot to false in config.inc.php. Finally, keep phpMyAdmin updated. Most installs come from the OS package manager, so regular apt updates cover it, and you can turn on automatic security updates to avoid falling behind.
Remove phpMyAdmin Safely When You Do Not Need It
If you only open phpMyAdmin once a month, or never, the safest setup is no phpMyAdmin at all. An app that is not installed cannot be attacked. To remove phpMyAdmin safely, back up first: use the guide to back up MySQL databases automatically with mysqldump and cron and confirm the backup file exists before you touch anything.
Then remove the package and its leftover files:
sudo apt remove --purge phpmyadmin
sudo rm -rf /usr/share/phpmyadmin /etc/phpmyadmin
sudo systemctl reload apache2 # or nginx
Check the web server config for any leftover Alias or location block that points to phpMyAdmin and delete it. Then open the old URL in a browser. It should return 404. If it still loads, a config file is still pointing at it, so search the web server config directory for “phpmyadmin” and remove what you find. Test your sites after removal. WordPress and other apps connect to MySQL directly, so they keep working, but check one page and one admin login to be sure.
Manage MySQL Without phpMyAdmin: Adminer and the CLI
Removing phpMyAdmin does not mean losing a visual tool. Adminer vs phpMyAdmin comes down to exposure: Adminer is a single PHP file you upload only when you need it and delete when you finish. That habit alone removes the permanent target. If you keep it on the server, protect it with the same steps above: a private URL, a second password, and an IP check.
The MySQL command line covers the rest. Log in with mysql -u root -p, then:
SHOW DATABASES;
USE your_database;
SHOW TABLES;
SELECT * FROM wp_options LIMIT 5;
For backups, mysqldump does the job from a cron job with no web interface at all. Most daily database work, checking a table, fixing a value, or exporting a backup, takes a few commands once you know them.
Common Mistakes That Undo Your Hardening
- Changing the URL but leaving the old /phpmyadmin path active as well.
- Using the same password for the extra login and the MySQL account.
- Opening MySQL port 3306 to the internet “just for a minute” and forgetting to close it.
- Skipping updates for months, then wondering why an old version has a known hole.
- Sharing the phpMyAdmin URL in a chat or ticket where other people can see it.
What to Do After You Lock It Down
Once it is locked down, test it like an attacker would. Try the old URL and confirm it returns 404. Try logging in from a different IP and confirm the IP check blocks you. Check the web server access log for requests to /phpmyadmin and confirm they now fail. Then set a monthly reminder to check for phpMyAdmin updates and review the access log again. A locked-down phpMyAdmin is not a one-time job, but after these steps the maintenance is small: update it, check the logs, and keep the URL private.