How to Secure phpMyAdmin on a Server

phpMyAdmin is a favourite target: move it off the default URL, restrict by IP, add a second password, force HTTPS, disable root — or skip installing it.

Published
Reading time
3 min

phpMyAdmin is a web page that can run any SQL against your databases with a valid login. Scanners request /phpmyadmin/, /pma/, /mysql/ and thirty other paths on every server on the internet, every day, then try root with a password list. Left at its defaults it is the easiest way into a server that does not have it exposed for a reason. Here is how to run it safely, and the alternatives.

Do you need it exposed at all?

Plesk includes phpMyAdmin behind the panel's own login: Databases → phpMyAdmin opens it authenticated as the database user without a separate public URL. If you are on Plesk, that is the secure configuration already — do not install a second copy under a site. For a plain server, the alternatives below may mean you do not need a web-facing copy either.

1. Move it off the default path

If it is served by Apache or Nginx at /phpmyadmin, change the alias to something unguessable:

nginx
# Nginx
location /db-c7f2a9/ {
    alias /usr/share/phpmyadmin/;
    ...
}
apache
# Apache: /etc/phpmyadmin/apache.conf or the site config
Alias /db-c7f2a9 /usr/share/phpmyadmin

This removes you from the automated scans, which is most of the risk. It is not sufficient on its own.

2. Restrict by IP

nginx
location /db-c7f2a9/ {
    allow 198.51.100.7;      # office
    allow 203.0.113.0/24;    # VPN range
    deny all;
    ...
}
apache
<Directory /usr/share/phpmyadmin>
    Require ip 198.51.100.7 203.0.113.0/24
</Directory>

If your address changes, use a VPN with a fixed exit (WireGuard on a VPS) and allow only that.

3. Add HTTP basic auth in front

A second password before phpMyAdmin's own login page appears:

bash
sudo apt install apache2-utils -y
sudo htpasswd -c /etc/nginx/.pma_htpasswd admin
nginx
location /db-c7f2a9/ {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.pma_htpasswd;
    ...
}

Brute-forcing now requires two independent credentials, and the phpMyAdmin login page never loads for anyone without the first.

4. HTTPS only

phpMyAdmin sends database passwords in the login form. Serve it only over TLS; in config.inc.php:

php
$cfg['ForceSSL'] = true;

5. No root login

Root should not log in over the web at all. In config.inc.php:

php
$cfg['Servers'][$i]['AllowRoot'] = false;

Give each site's database user access to its own database only (GRANT ALL ON example_db.* TO ...), and log in as that user. A compromised phpMyAdmin session then reaches one database, not all of them.

6. Keep it updated and configured

phpMyAdmin has had serious vulnerabilities; update it with the system packages, or if installed by hand, from the official site. Set a random blowfish_secret, disable the setup directory (delete it), and set $cfg['LoginCookieValidity'] to a short value (e.g. 900 seconds).

7. Fail2ban

Ban IPs that fail phpMyAdmin's login repeatedly. It logs to syslog with $cfg['AuthLog'] = 'syslog', and Fail2ban ships a phpmyadmin-syslog jail:

ini
[phpmyadmin-syslog]
enabled = true

Alternatives that avoid the problem

  • SSH tunnel + local client. Bind MySQL to 127.0.0.1 (it should be anyway), then from your machine: ssh -L 3307:127.0.0.1:3306 user@server and connect a desktop client (TablePlus, DBeaver, MySQL Workbench, Sequel Ace) to localhost:3307. Nothing is exposed on the web; authentication is your SSH key.
  • The command line. mysql on the server over SSH does everything phpMyAdmin does, without a web surface.
  • Adminer — a single-file alternative, easier to hide and to remove when not in use. Same restrictions apply.

Check your exposure

bash
curl -sI https://example.com/phpmyadmin/ | head -1
curl -sI https://example.com/pma/ | head -1

Anything other than 404 or 403 from the public internet is a page an attacker can reach. Plesk's built-in copy answers only inside the panel session; a copy someone installed into a site's httpdocs years ago is the one to look for.

On VPSPioneer shared plans, phpMyAdmin is available only through the Plesk login with the panel's 2FA in front; on a managed VPS we do not install a public copy at all, and set up the SSH tunnel method for whoever needs a GUI.

#security#phpmyadmin#mysql#plesk#hardening

Keep reading

More from Security

All guides

Security

How to Enable Two-Factor Authentication for Plesk and WordPress

Turn on 2FA for the Plesk panel and every WordPress admin, choose an authenticator app, keep recovery codes, and enforce it so a leaked password is not enough.

3 min read →

Security

How to Set Up Automatic Backups (and Actually Test the Restore)

The 3-2-1 rule for a web server, what to back up and how often, Plesk and command-line methods, off-site storage, and the restore test most people never do.

4 min read →

Security

First 10 Things to Do on a New Linux VPS (Security Checklist)

A 30-minute copy-paste checklist for a fresh Debian, Ubuntu or AlmaLinux VPS, with a verification command after every step so you know it worked.

6 min read →