> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Install phpMyAdmin with Nginx on Ubuntu and Debian

> Install phpMyAdmin with Nginx: sudo apt install phpmyadmin, choose no web server, add a hidden Nginx location with a password prompt, log in with a DB user.

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`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Intermediate | 15–20 minutes | Ubuntu 22.04 / 24.04, Debian 12 | Nginx, PHP-FPM and MariaDB or MySQL already installed, sudo access |

## Before you start

* You need a working Nginx + PHP-FPM + MariaDB setup. See [install a LEMP stack](https://help.freakhosting.com/portals/other/how-to-install-a-lemp-stack.md).
* Use HTTPS, so your database password is never sent in plain text. See [get a free SSL certificate with Certbot](https://help.freakhosting.com/portals/other/how-to-get-a-free-ssl-certificate-with-certbot.md).
* 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.

> [!TIP]
>
> If you only need occasional access, you can skip phpMyAdmin and use [HeidiSQL over an SSH tunnel](https://help.freakhosting.com/portals/other/how-to-connect-to-database-using-heidisql.md) instead. Nothing extra is exposed to the internet.

## How to install phpMyAdmin

**1. Install the packages**

```bash theme={null}
sudo apt update
sudo apt install phpmyadmin php-mbstring
```

**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](https://docs.phpmyadmin.net/en/latest/setup.html) 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`:

```bash theme={null}
sudo ln -s /usr/share/phpmyadmin /var/www/html/dbadmin-7f3k
```

**2. Create a login for the password prompt**

```bash theme={null}
sudo apt install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd alex
```

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:

```nginx theme={null}
location ^~ /dbadmin-7f3k {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location ~ ^/dbadmin-7f3k/(libraries|templates|sql)/ {
        deny all;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
}
```

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**

```bash theme={null}
sudo nginx -t
sudo systemctl reload nginx
```

`nginx -t` must say `syntax is ok` and `test is successful` before you reload.

> [!WARNING]
>
> 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:

```bash theme={null}
sudo mariadb
```

```sql theme={null}
CREATE USER 'pmaadmin'@'localhost' IDENTIFIED BY 'Str0ng-Admin-Pass!';
GRANT ALL PRIVILEGES ON *.* TO 'pmaadmin'@'localhost' WITH GRANT OPTION;
EXIT;
```

For day-to-day work on one site, log in with that site's own user instead. See [create a database and user](https://help.freakhosting.com/portals/other/how-to-create-a-mysql-database-and-user.md).

## 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

| Measure | How |
| - | - |
| Allow only your IP | Add `allow 198.51.100.25;` and `deny all;` at the top of the `location ^~ /dbadmin-7f3k` block |
| HTTPS only | Issue a certificate with [Certbot](https://help.freakhosting.com/portals/other/how-to-get-a-free-ssl-certificate-with-certbot.md) and redirect HTTP to HTTPS |
| Block repeated guessing | Watch for failed logins with [Fail2ban](https://help.freakhosting.com/portals/other/how-to-set-up-fail2ban-for-ssh-on-ubuntu.md) |
| Keep it updated | `sudo apt upgrade` installs phpMyAdmin security fixes. See [enable automatic security updates](https://help.freakhosting.com/portals/other/how-to-enable-automatic-security-updates.md) |
| Remove when unused | `sudo rm /var/www/html/dbadmin-7f3k` removes the link only, not phpMyAdmin |

## 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](https://help.freakhosting.com/portals/other/how-to-fix-502-bad-gateway-nginx.md).

### 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](https://help.freakhosting.com/portals/other/how-to-install-apache.md).

### Is phpMyAdmin included on FREAKHOSTING panels?

The Game Panel and Web Panel already have phpMyAdmin built in. See [Game Panel databases](https://help.freakhosting.com/portals/game-panel/how-to-manage-databases.md) and [Web Panel databases](https://help.freakhosting.com/portals/web-panel/how-to-manage-mysql-databases.md). This guide is for your own VPS or dedicated server.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Install a LEMP stack](https://help.freakhosting.com/portals/other/how-to-install-a-lemp-stack.md)
>
> Nginx, PHP and MariaDB first.

> [card] [Secure MySQL and MariaDB](https://help.freakhosting.com/portals/other/how-to-secure-mysql-and-mariadb.md)
>
> Harden the database itself.

> [card] [Set up Nginx server blocks](https://help.freakhosting.com/portals/other/how-to-set-up-nginx-server-blocks.md)
>
> Where the location block goes.

> [card] [Connect with HeidiSQL](https://help.freakhosting.com/portals/other/how-to-connect-to-database-using-heidisql.md)
>
> A desktop alternative over SSH.

***

> [!NOTE]
>
> **Checked against the official [phpMyAdmin documentation](https://docs.phpmyadmin.net/en/latest/setup.html) and [nginx documentation](https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html)** 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.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.