phpMyAdmin is a free, open-source PHP application that provides a browser-based interface for managing MySQL and MariaDB servers. It lets you create and delete databases, manage user accounts and privileges, run SQL queries, and import or export data in formats including CSV, SQL, and JSON. All of this works without touching the MySQL command line.
This guide covers how to install phpMyAdmin on Ubuntu 18.04 with Apache and how to secure it with an extra layer of HTTP Basic Authentication. Before starting, make sure the LAMP stack (Linux, Apache, MySQL, PHP) is already installed and running on your server.
<strong>Prerequisite:</strong> You need sudo access and an existing LAMP installation.
Update the package list and install phpMyAdmin:
bashsudo apt update && sudo apt upgradesudo apt install phpmyadmin
The installer runs an interactive wizard with three prompts:
apache2, then press Enter. This automatically configures Apache to serve phpMyAdmin at /phpmyadmindbconfig-common, select Yes. This creates phpMyAdmin’s internal configuration database without manual SQL stepsAfter the wizard completes, restart Apache to load the phpMyAdmin configuration:
bashsudo systemctl restart apache2
In Ubuntu systems running MySQL 5.7 and later, the root account uses the auth_socket authentication plugin by default. This plugin validates connections through the Unix socket, not a password. You cannot log in to phpMyAdmin as root using a password.
Instead, create a dedicated MySQL admin user with mysql_native_password authentication:
bashsudo mysql
sqlCREATE USER 'padmin'@'localhost' IDENTIFIED BY 'super-strong-password';GRANT ALL PRIVILEGES ON *.* TO 'padmin'@'localhost' WITH GRANT OPTION;
WITH GRANT OPTION gives this user the ability to create other MySQL users and grant them permissions — the same capability the root account has. Use a strong password and note it down.
Open https://your_domain_or_ip/phpmyadmin in a browser and log in with the padmin credentials you just created. The phpMyAdmin dashboard shows your databases in the left sidebar and server information in the main panel. Use the interface to create databases, run queries, import and export data, and manage user accounts.
The /phpmyadmin URL is publicly known and frequently targeted by automated scanners. Adding HTTP Basic Auth creates a second authentication barrier before the phpMyAdmin login form appears.
Create the Basic Auth password file using Apache’s htpasswd tool. The -c flag creates the file. To add more users later, run the same command without -c:
bashsudo htpasswd -c /etc/phpmyadmin/.htpasswd padmin
Edit the Apache phpMyAdmin configuration at /etc/apache2/conf-available/phpmyadmin.conf. Inside the <Directory /usr/share/phpmyadmin> block, add these directives:
apacheAuthType basicAuthName "Authentication Required"AuthUserFile /etc/phpmyadmin/.htpasswdRequire valid-user
Restart Apache to apply the changes:
bashsudo systemctl restart apache2
Accessing /phpmyadmin now prompts for the Basic Auth credentials first, then the phpMyAdmin MySQL login form. Anyone without the Basic Auth password cannot reach the phpMyAdmin login page at all.
One more security step. Rename the default /phpmyadmin alias to something less predictable, such as /dbadmin or a random string. Change the Alias directive in /etc/apache2/conf-available/phpmyadmin.conf and restart Apache. This significantly reduces automated scan traffic targeting your admin panel.
phpMyAdmin is now installed and secured on your Ubuntu 18.04 server. Use it to manage databases, create users, run queries, and handle data imports and exports through the browser. Leave a comment below if you run into any issues.