Introduction

phpMyAdmin is the most popular web-based administration tool for MySQL and MariaDB. Instead of typing SQL into a terminal every time you need to create a database, add a user, or import a dump, you get a clean browser interface where all of it takes a few clicks. It is free, open source, and battle-tested on millions of servers.

In this guide you will install phpMyAdmin on Ubuntu 24.04 LTS (with notes where Ubuntu 22.04 LTS differs), wired into Apache so it is served at http://your-server-ip/phpmyadmin. You will create a dedicated MySQL admin user (because Ubuntu's MySQL root login works differently than most people expect), enable the Apache configuration, verify everything works, and harden the setup so it is not an open target for brute-force bots. This guide assumes a standard LAMP-style server; if you do not have Apache or MySQL yet, Step 1 installs them.

Prerequisites

  • Ubuntu 24.04 LTS or 22.04 LTS server (a VPS or local VM works fine).
  • A non-root user with sudo privileges.
  • Apache and MySQL/MariaDB installed — Step 1 covers this if you have not done it yet.
  • PHP 8.1+ with the mysqli extension — Step 1 covers this too.
  • Your server's public IP address or domain name for the final browser check.

Step 1 — Install Apache, MySQL, and PHP

First, refresh the package index and install all updates so you are building on a clean base.

sudo apt update && sudo apt upgrade -y

The apt update command downloads the latest package lists, and apt upgrade applies pending updates. Skipping this can leave you with outdated PHP builds that phpMyAdmin's dependencies refuse to work with.

Now install Apache, MySQL, and PHP with the extensions phpMyAdmin needs:

sudo apt install -y apache2 mysql-server php php-mysqli php-mbstring php-zip php-gd php-curl

This installs apache2 (the web server), mysql-server (the database), and php along with the extensions phpMyAdmin depends on: mysqli for talking to MySQL, mbstring for character-set handling, zip and gd for import/export features, and curl for version checks. On Ubuntu 24.04 this pulls in PHP 8.3, on 22.04 it pulls in PHP 8.1 — phpMyAdmin 5.2+ supports both. If you already have a LAMP stack, the command simply fills in any missing pieces.

Confirm Apache and MySQL are running:

sudo systemctl status apache2 --no-pager
sudo systemctl status mysql --no-pager

Both should show active (running). If either is inactive, start it with sudo systemctl start apache2 (or mysql) and enable it at boot with sudo systemctl enable apache2 mysql.

Step 2 — Create a Dedicated MySQL Admin User for phpMyAdmin

This is the step most tutorials gloss over, and it is the reason most phpMyAdmin logins fail on Ubuntu. On Ubuntu's MySQL package, the root user authenticates with the auth_socket plugin, which means it can only log in as the operating-system root user — it has no password and cannot log in through a web form at all.

The correct fix is a dedicated admin user with password authentication. Open the MySQL shell (root via sudo needs no password):

sudo mysql

Then run these statements, replacing the placeholder with a genuinely strong password:

CREATE USER 'pmaadmin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Replace-With-A-Strong-Password';
GRANT ALL PRIVILEGES ON *.* TO 'pmaadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

CREATE USER makes a new MySQL account restricted to localhost, using the classic password authentication plugin that phpMyAdmin understands. GRANT ALL PRIVILEGES ON *.* gives it full control over every database — the same power root has — and FLUSH PRIVILEGES reloads the grant tables immediately.

Security note: Never reuse this password elsewhere, and store it in a password manager. This account is a full database superuser; if you only need phpMyAdmin for one application, create a narrower user with privileges limited to that database instead.

Step 3 — Install phpMyAdmin from the Ubuntu Repositories

With the database user ready, install phpMyAdmin itself:

sudo apt install -y phpmyadmin

During installation, Ubuntu's debconf prompts ask you two questions. Answer them carefully:

  1. Web server to configure automatically: press Space to select apache2 (an asterisk appears next to it), then Tab to highlight OK and press Enter. This wires phpMyAdmin's Apache config file in automatically.
  2. Configure database for phpmyadmin with dbconfig-common? Choose Yes. dbconfig-common creates the small internal database phpMyAdmin uses for features like bookmarked queries and relation view, and it sets a random password for the internal phpmyadmin database user.

That is the entire installation. The package drops phpMyAdmin's files into /usr/share/phpmyadmin and its Apache snippet into /etc/apache2/conf-available/phpmyadmin.conf.

Step 4 — Enable the phpMyAdmin Apache Configuration

Selecting apache2 in the debconf prompt usually enables the configuration automatically, but verify it explicitly — a missing enable is the number-one cause of 404 errors (see the troubleshooting section). Run:

sudo a2enconf phpmyadmin
sudo systemctl reload apache2

a2enconf phpmyadmin creates a symlink from conf-enabled to the config file in conf-available, which tells Apache to load it. systemctl reload apache2 makes Apache re-read its configuration without dropping active connections.

Take a look at what was enabled — the key line is the Alias:

grep -E "^Alias" /etc/apache2/conf-available/phpmyadmin.conf

You should see Alias /phpmyadmin /usr/share/phpmyadmin, which maps the URL path /phpmyadmin to the files on disk. If a2enconf reported "Conf phpmyadmin already enabled", everything was already wired correctly and the reload was harmless.

Step 5 — Harden phpMyAdmin Access (Recommended)

A default phpMyAdmin install sits at a predictable URL and is hammered by brute-force bots within hours of going public. Spend five minutes on at least one of these hardening options.

Option A: Rename the public URL

Security through obscurity is not a strategy on its own, but a non-standard URL cuts automated scan traffic to near zero. Edit the config:

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Change the line Alias /phpmyadmin /usr/share/phpmyadmin to something unguessable, for example Alias /db-panel-9x7q /usr/share/phpmyadmin. Save, exit, and reload Apache with sudo systemctl reload apache2.

Option B: Add HTTP Basic Authentication in front

This adds a second password prompt before phpMyAdmin itself loads — an attacker now has to beat two logins. First create the password file (install apache2-utils if htpasswd is missing):

sudo apt install -y apache2-utils
sudo htpasswd -c /etc/phpmyadmin/.htpasswd dbadmin

The -c flag creates the file; omit it when adding further users. Then add an access block inside /etc/apache2/conf-available/phpmyadmin.conf, right after the Alias line:

<Directory /usr/share/phpmyadmin>
    AllowOverride None
    AuthType Basic
    AuthName "Restricted Area"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user
</Directory>

Save and reload Apache: sudo systemctl reload apache2. From now on, browsers ask for the dbadmin password before the phpMyAdmin login screen even appears.

Step 6 — Log In Through Your Browser

Open http://YOUR_SERVER_IP/phpmyadmin (or your renamed URL from Step 5) in a browser. You should see the phpMyAdmin login page. Log in with the username pmaadmin and the strong password you set in Step 2.

On first login, check the bottom of the main page for warnings. A clean install on 24.04 typically shows no errors. If you see a warning about the phpmyadmin storage database not being configured, dbconfig-common already handled it — a page refresh usually clears the message.

Verify It Worked

Run these checks from the server to confirm the full chain — Apache config, PHP, and database connectivity — is healthy:

curl -s -o /dev/null -w "%{http_code}\n" http://localhost/phpmyadmin/

A 200 response means Apache is serving phpMyAdmin correctly. A 401 means your Basic Auth from Step 5 is active and working. A 404 means the Apache config is not enabled — jump to Fix 1 below.

sudo apache2ctl -M | grep -i php
sudo systemctl is-active apache2 mysql

The first command confirms the PHP module is loaded in Apache. The second should print active twice — once for Apache, once for MySQL. Finally, log in through the browser as pmaadmin and create a test database, then drop it. If you can create and delete a database through the web UI, the entire stack is working end to end.

Common Issues & Fixes

1. 404 Not Found when opening /phpmyadmin

Cause: The Apache configuration was never enabled (the debconf apache2 selection was skipped) or Apache was not reloaded afterwards. Fix:

sudo a2enconf phpmyadmin
sudo systemctl restart apache2

Then re-run the curl check. If it still 404s, verify the Alias line exists in /etc/apache2/conf-available/phpmyadmin.conf and that the symlink exists in /etc/apache2/conf-enabled/.

2. "Cannot log in to the MySQL server"

Cause: You tried to log in as root, which uses the auth_socket plugin on Ubuntu and cannot authenticate with a password. Fix: log in as the dedicated pmaadmin user from Step 2 instead. If you must use root, switch its plugin explicitly:

sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourStrongPassword'; FLUSH PRIVILEGES;"

The dedicated user is the safer choice — root over a web form is an unnecessary risk.

3. "The mysqli extension is missing" error page

Cause: PHP was installed without the MySQL driver, or Apache is loading a PHP version whose mysqli module is not installed. Fix:

sudo apt install -y php-mysqli
sudo systemctl restart apache2

The php-mysqli meta-package always matches your default PHP version (8.3 on 24.04, 8.1 on 22.04). Confirm with php -m | grep -i mysqli afterwards.

4. 403 Forbidden after hardening

Cause: The <Directory> block added in Step 5 is missing a Require directive, or an old config still has Require ip 127.0.0.1 from a template that only allows localhost. Fix: make sure the Directory block ends with Require valid-user (with Basic Auth) or Require all granted (without it), then sudo systemctl reload apache2.

5. Login loop or "Failed to set session cookie"

Cause: phpMyAdmin cannot write its session data — usually a missing blowfish_secret in the config, a full disk, or a broken PHP session directory. Fix: open /etc/phpmyadmin/config.inc.php and make sure $cfg['blowfish_secret'] is set to a random 32-character string; then check df -h for a full disk and ls -ld /var/lib/php/sessions for correct ownership. Clear your browser cookies for the site and try again.

Conclusion

You now have phpMyAdmin running on Ubuntu with Apache: the full PHP stack installed, a dedicated password-authenticated MySQL admin user, the Apache config enabled and verified, and at least one layer of hardening in front of the login page. From here you can manage databases, users, and imports entirely from your browser — while the troubleshooting section above covers the handful of errors that catch almost everyone on a fresh Ubuntu install.


Need help securing, tuning, or automating your server setup? XpertBees provides professional LAMP/LEMP server setup, hardening, and managed hosting support for businesses — reach out and we will handle the infrastructure while you focus on your product.