phpMyAdmin is an open-source, web-based tool for managing MySQL databases. Installing it gives you a browser interface for creating, modifying, and deleting databases, tables, and fields, managing users, importing and exporting data, and running SQL statements without touching the command line. This guide installs MySQL and phpMyAdmin on Ubuntu 24.04, creates a sample database and user, and secures the phpMyAdmin endpoint with an extra layer of basic authentication. By the end, you'll have a working phpMyAdmin installation running over Apache, protected against unauthenticated access.
1. Set Up the MySQL Database Server
1. Update the APT package index:
$ sudo apt update
2. Install MySQL server:
$ sudo apt install mysql-server -y
3. Log in to the MySQL server:
$ sudo mysql
4. Create a sample database:
mysql> CREATE DATABASE my_company;
5. Create a new MySQL user with a strong password, replacing your_password:
mysql> CREATE USER 'company_admin'@'localhost' IDENTIFIED BY 'your_password';
6. Grant the user full privileges on the database:
mysql> GRANT ALL PRIVILEGES ON my_company.* TO 'company_admin'@'localhost';
7. Flush privileges to apply the changes:
mysql> FLUSH PRIVILEGES;
8. Exit the MySQL console:
mysql> EXIT;
2. Install phpMyAdmin
phpMyAdmin is available in the default package repositories on Ubuntu 24.04.
1. Update the APT package index:
$ sudo apt update
2. Install PHP and the required extensions:
$ sudo apt install php php-mysql php-mbstring php-json php-xml php-curl php-zip php-common -y
3. Install phpMyAdmin:
$ sudo apt install phpmyadmin -y
During setup, select apache2 as the web server to reconfigure automatically, keep the database configuration for phpMyAdmin set to Yes, and set a strong phpMyAdmin database password when prompted (enter it twice to confirm).
4. Verify the installation succeeded:
$ dpkg -l | awk '/phpmyadmin / {print}'
Output:
ii phpmyadmin 4:5.2.1+dfsg-3 all MySQL web administration tool
3. Configure phpMyAdmin
phpMyAdmin ships with a default Apache virtual host configuration that serves the /phpmyadmin endpoint using your server's IP or domain.
1. Enable the phpMyAdmin virtual host configuration:
$ sudo a2enconf phpmyadmin.conf
2. Restart Apache to apply the configuration changes:
$ sudo systemctl restart apache2
3. Confirm Apache is running:
$ sudo systemctl status apache2
4. Check the UFW status:
$ sudo ufw status
If UFW isn't installed, install it and allow SSH:
$ sudo apt install ufw -y && sudo ufw allow ssh
5. Allow the Apache Full profile through the firewall to enable HTTP and HTTPS:
$ sudo ufw allow 'Apache Full'
6. Reload UFW to apply the changes:
$ sudo ufw reload
4. Access phpMyAdmin
1. Open the phpMyAdmin endpoint in a browser using your server's IP address or domain name:
http://your_server_ip/phpmyadmin
2. Log in using the company_admin credentials you created earlier, then select the my_company database from the left navigation menu to manage it.
Avoid logging in to phpMyAdmin with the MySQL root account — accidental deletions, modifications, and security vulnerabilities are far more consequential from a superuser account. Always create a dedicated user scoped to the database(s) it actually needs.
5. Secure the phpMyAdmin Endpoint
Basic authentication adds a second password prompt in front of the phpMyAdmin interface.
1. Create an .htpasswd file with a new username, replacing your_username:
$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_username
2. Open the phpMyAdmin Apache configuration:
$ sudo nano /etc/apache2/conf-available/phpmyadmin.conf
3. Add the AllowOverride All directive inside the /usr/share/phpmyadmin directory block, so it looks like this:
<Directory /usr/share/phpmyadmin>
AllowOverride All
...
</Directory>
4. Create a new .htaccess file:
$ sudo nano /usr/share/phpmyadmin/.htaccess
5. Add the following authentication configuration to the file:
AuthType Basic
AuthName "Restricted Access to PhpMyAdmin"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
AuthType Basic sets the authentication type, AuthName sets the message shown in the sign-in prompt, AuthUserFile points to the file with allowed users and encrypted passwords, and Require valid-user enforces that a valid user must authenticate.
6. Restart Apache to apply the configuration changes:
$ sudo systemctl restart apache2
7. Reload the phpMyAdmin URL and confirm you're prompted for the new username and password, then log in with your MySQL credentials to manage databases:
http://your_server_ip/phpmyadmin
6. Troubleshoot phpMyAdmin
phpMyAdmin login fails:
$ sudo systemctl status mysql
Double-check your MySQL username and password, and review the config file for errors:
$ sudo nano /etc/phpmyadmin/config.inc.php
Internal Server Error:
$ sudo tail -f /var/log/apache2/error.log
Reinstall the required PHP extensions if any are missing:
$ sudo apt install php-mysql php-mbstring php-json php-xml php-curl php-zip php-common -y
Access Denied:
$ sudo mysql
mysql> CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'localhost' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Next Steps
- Create additional MySQL users scoped to individual databases instead of reusing one admin account.
- Put phpMyAdmin behind HTTPS with a reverse proxy or Apache TLS configuration.
- Automate MySQL backups before making structural changes through phpMyAdmin.
- Review Apache and MySQL logs periodically for unusual login attempts.
For the full guide with additional tips, visit the original article on Vultr Docs.
Top comments (0)