Skip to main content
To install phpMyAdmin with Nginx on Ubuntu or Debian, run sudo apt install phpmyadmin, select no web server when asked, link /usr/share/phpmyadmin into your site’s web root under a hard-to-guess path, add an Nginx location block that passes PHP to PHP-FPM, protect it with a second password, and log in with a dedicated database user rather than root.

Before you start

  • You need a working Nginx + PHP-FPM + MariaDB setup. See install a LEMP stack.
  • Use HTTPS, so your database password is never sent in plain text. See get a free SSL certificate with Certbot.
  • phpMyAdmin is a web page for managing MySQL and MariaDB databases in your browser. Because it is public, bots look for it. The steps below hide and lock it down.
If you only need occasional access, you can skip phpMyAdmin and use HeidiSQL over an SSH tunnel instead. Nothing extra is exposed to the internet.

How to install phpMyAdmin

1

Install the packages

2

Choose no web server

At Web server to reconfigure automatically, the choices are apache2 and lighttpd. Select neither: make sure no box has a *, then press Tab to reach Ok and press Enter.
3

Answer the database question

At Configure database for phpmyadmin with dbconfig-common? choose No for a simple setup. phpMyAdmin works without it; choosing Yes creates an extra phpmyadmin database for optional features such as bookmarks. You can change this later with sudo dpkg-reconfigure phpmyadmin.
The files are in /usr/share/phpmyadmin and the configuration in /etc/phpmyadmin, as the phpMyAdmin documentation notes for Debian and Ubuntu packages.

How to set up phpMyAdmin in Nginx

1

Link phpMyAdmin into your web root

Pick a path that is not easy to guess. This example uses dbadmin-7f3k and the default web root /var/www/html:
2

Create a login for the password prompt

Type a password twice. This is a second lock in front of phpMyAdmin, separate from your database login. Leave out -c when adding more users later.
3

Add a location block

Open your site’s server block, for example /etc/nginx/sites-available/default, and add inside the server { … } block:
Use the PHP-FPM socket for your PHP version: php8.3-fpm.sock on Ubuntu 24.04 and php8.2-fpm.sock on Debian 12. Run ls /run/php/ to see yours. The deny rule blocks phpMyAdmin’s internal folders, as the phpMyAdmin documentation recommends.
4

Test and reload Nginx

nginx -t must say syntax is ok and test is successful before you reload.
Always run sudo nginx -t before reloading. A broken config can take every site on the server offline. If the test fails, fix the line it names or remove the new block.

How to create a database user for phpMyAdmin

On Ubuntu and Debian, the database root user logs in through the Linux socket, so phpMyAdmin cannot sign in as root. You see Access denied for user 'root'@'localhost'. Create an admin user instead:
For day-to-day work on one site, log in with that site’s own user instead. See create a database and user.

How to check it worked

  1. Open https://example.com/dbadmin-7f3k/ in your browser.
  2. Enter the Nginx login you made with htpasswd.
  3. On the phpMyAdmin page, log in with pmaadmin and its password.
You see your databases in the left-hand list.

How to lock phpMyAdmin down further

Frequently asked questions

Why do I get 502 Bad Gateway?

Nginx cannot reach PHP-FPM. Check that the socket path in fastcgi_pass matches a file in /run/php/ and that PHP-FPM is running. See fix 502 Bad Gateway in Nginx.

Why does my browser download index.php instead of opening it?

The location ~ \.php$ block is missing or outside the phpMyAdmin block, so Nginx sends the file as-is. Check the block and reload Nginx.

Can I use phpMyAdmin with Apache instead?

Yes. Choose apache2 at the web server question and the package configures it for you. See install Apache.

Is phpMyAdmin included on FREAKHOSTING panels?

The Game Panel and Web Panel already have phpMyAdmin built in. See Game Panel databases and Web Panel databases. This guide is for your own VPS or dedicated server.

VPS and dedicated server guides

Every guide in this section.

Install a LEMP stack

Nginx, PHP and MariaDB first.

Secure MySQL and MariaDB

Harden the database itself.

Set up Nginx server blocks

Where the location block goes.

Connect with HeidiSQL

A desktop alternative over SSH.

Checked against the official phpMyAdmin documentation and nginx documentation on 4 November 2026; package install, Nginx config (nginx -t), password prompt, folder blocking and database login tested on Ubuntu 24.04 LTS with phpMyAdmin 5.2.1, Nginx 1.24, PHP 8.3 and MariaDB 10.11. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026