Log inSign up

phpMyAdmin with HTTPS, an extra password and limited access

Install phpMyAdmin with sudo apt install phpmyadmin, let it hook into Apache, then lock it down: serve it only over HTTPS, change the public path, wrap it in an HTTP basic auth password and allow only your own IP addresses. Log in with a dedicated database admin account instead of root. If you never need it from a browser on the open internet, keep it on localhost and reach it through an SSH tunnel.

Topic: PHP and web stacks · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

What should be in place before installing phpMyAdmin?

phpMyAdmin is a PHP application, so it needs a web server with PHP and a MariaDB or MySQL server already running. The quickest base is the LAMP stack; an existing LEMP server works too with one extra Nginx block shown later. You also want a DNS name for the server so a real certificate can be issued, for example db.example.net or the main site name. Check what is running:

systemctl status apache2 mariadb --no-pager
php -v
mariadb --version

Because the tool can read and change every table it can reach, treat its login page as one of the most sensitive URLs on the server. Everything below is about reducing who can even see that page.

How do you install phpMyAdmin from the repositories?

The package lives in Ubuntu's universe component and in Debian main. It brings the PHP extensions it needs and registers its own small database for settings through dbconfig-common.

sudo apt update
sudo apt install -y phpmyadmin php-mbstring php-zip php-gd php-curl
apt policy phpmyadmin

The installer asks two questions. For the web server, press space to mark apache2 (choose nothing if you use Nginx). For Configure database for phpmyadmin with dbconfig-common, answer yes and let it set a random password for its control user. The package then links /etc/phpmyadmin/apache.conf into /etc/apache2/conf-available/phpmyadmin.conf and enables it, which publishes the app at /phpmyadmin. The apt policy line shows which version your release ships, so you know which changelog to read.

Which database account should you log in with?

Create a separate administrative user and use that, not root. On Ubuntu and Debian the database root account authenticates through the Unix socket, so it cannot log in through a web form anyway, and it is better left that way.

sudo mariadb
CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'a-long-unique-passphrase';
GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

If you only manage one application database, grant on appdb.* instead of *.*, which limits the damage of a leaked password. Then tell phpMyAdmin to refuse root and empty passwords outright with a small file in its conf.d folder:

sudo nano /etc/phpmyadmin/conf.d/hardening.php
<?php
$cfg['Servers'][1]['AllowRoot'] = false;
$cfg['Servers'][1]['AllowNoPassword'] = false;
$cfg['LoginCookieValidity'] = 1800;

The last line signs users out after 30 minutes of inactivity.

How do you move phpMyAdmin off the default path?

Automated scanners request /phpmyadmin on every server they find, so a different path removes most of that noise. Edit the alias in the package config:

sudo nano /etc/phpmyadmin/apache.conf
# change
Alias /phpmyadmin /usr/share/phpmyadmin
# to something of your own, for example
Alias /dbpanel-7q4k /usr/share/phpmyadmin

sudo apachectl configtest && sudo systemctl reload apache2

A hidden path is not protection by itself; it only cuts log clutter. The real barriers are TLS, the second password and the IP list in the next steps.

How do you add a second login with HTTP basic auth?

An Apache password in front of the app means attackers must pass two separate logins before they reach the database prompt. Create the password file outside the web root:

sudo apt install -y apache2-utils
sudo htpasswd -c -B /etc/phpmyadmin/.htpasswd deploy
sudo chown root:www-data /etc/phpmyadmin/.htpasswd
sudo chmod 640 /etc/phpmyadmin/.htpasswd

Then add these lines inside the existing <Directory /usr/share/phpmyadmin> block of /etc/phpmyadmin/apache.conf:

    AuthType Basic
    AuthName "Restricted"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    <RequireAll>
        Require valid-user
        Require ip 198.51.100.24 2001:db8:4f2a::/64
    </RequireAll>

Replace the addresses with your office or home IPs. RequireAll means a visitor needs both a listed IP and the basic auth password. If your own address changes often, drop the Require ip line and rely on the password plus Fail2ban watching the Apache error log.

How do you force HTTPS for the panel?

Basic auth sends the password with every request, so it must only travel over TLS. Issue a certificate for the site name and let Certbot add the redirect.

sudo ufw allow 'Apache Full'
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d db.example.net --redirect
sudo apachectl configtest && sudo systemctl reload apache2

Current phpMyAdmin releases leave the HTTPS redirect to the web server, which is exactly what Certbot just configured. Test from your machine with curl -I http://db.example.net/dbpanel-7q4k/: it should answer with a redirect to https://, and the HTTPS URL should return 401 until you supply the basic auth user.

Can phpMyAdmin run behind Nginx instead?

Yes. Skip the Apache choice during install, then add a location to an existing HTTPS server block that sends PHP to PHP-FPM:

location ^~ /dbpanel-7q4k/ {
    alias /usr/share/phpmyadmin/;
    index index.php;
    auth_basic "Restricted";
    auth_basic_user_file /etc/phpmyadmin/.htpasswd;
    allow 198.51.100.24;
    deny all;
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
}

Set the socket name to your PHP version, run sudo nginx -t and reload. Create the password file with htpasswd from apache2-utils just as above.

Is an SSH tunnel a better option?

For a single administrator it usually is: keep phpMyAdmin reachable only from the server itself and forward a local port over SSH when you need it. Change the Apache rule to Require local, reload, then from your workstation run:

ssh -L 8080:127.0.0.1:80 deploy@198.51.100.24
# then open http://127.0.0.1:8080/dbpanel-7q4k/ in your browser

Nothing about the panel is exposed to the internet, and SSH key login (see SSH keys and hardening) protects the only way in.

How do you keep phpMyAdmin maintained?

Updates arrive through normal package upgrades, so sudo apt update && sudo apt upgrade covers both the app and its PHP libraries. Read /var/log/apache2/error.log now and then for repeated failed logins. If you stop using the tool, disable it completely with sudo a2disconf phpmyadmin and a reload, or purge the package; an unused admin panel is pure risk.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2web server, PHP and MariaDB together1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4larger databases and imports2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months

Questions about phpMyAdmin behind HTTPS

Why can I not log in as root?

On Ubuntu and Debian the root database account uses socket authentication, and the hardening file blocks root as well. Use the separate admin user you created.

What is the phpmyadmin database user for?

It stores phpMyAdmin features such as bookmarks and saved queries. The installer creates it with a random password; you never log in with it.

Can I import a large SQL dump through phpMyAdmin?

Uploads are limited by upload_max_filesize and post_max_size. For big dumps, copy the file over SSH and run mariadb appdb < dump.sql instead.

Does phpMyAdmin work with PostgreSQL?

No, it handles MySQL and MariaDB only. Adminer supports PostgreSQL, SQLite and others in a single file.

Is changing the URL enough to keep it safe?

No. It only reduces scanner traffic. Keep HTTPS, the second password and an IP rule or SSH tunnel in place.