DEV Community

Cover image for Installing phpMyAdmin on Ubuntu 24.04
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya Originally published at docs.vultr.com

Installing phpMyAdmin on Ubuntu 24.04

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
Enter fullscreen mode Exit fullscreen mode

2. Install MySQL server:

$ sudo apt install mysql-server -y
Enter fullscreen mode Exit fullscreen mode

3. Log in to the MySQL server:

$ sudo mysql
Enter fullscreen mode Exit fullscreen mode

4. Create a sample database:

mysql> CREATE DATABASE my_company;
Enter fullscreen mode Exit fullscreen mode

5. Create a new MySQL user with a strong password, replacing your_password:

mysql> CREATE USER 'company_admin'@'localhost' IDENTIFIED BY 'your_password';
Enter fullscreen mode Exit fullscreen mode

6. Grant the user full privileges on the database:

mysql> GRANT ALL PRIVILEGES ON my_company.* TO 'company_admin'@'localhost';
Enter fullscreen mode Exit fullscreen mode

7. Flush privileges to apply the changes:

mysql> FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

8. Exit the MySQL console:

mysql> EXIT;
Enter fullscreen mode Exit fullscreen mode

2. Install phpMyAdmin

phpMyAdmin is available in the default package repositories on Ubuntu 24.04.

1. Update the APT package index:

$ sudo apt update
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

3. Install phpMyAdmin:

$ sudo apt install phpmyadmin -y
Enter fullscreen mode Exit fullscreen mode

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}'
Enter fullscreen mode Exit fullscreen mode

Output:

ii  phpmyadmin                           4:5.2.1+dfsg-3                          all          MySQL web administration tool
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

2. Restart Apache to apply the configuration changes:

$ sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

3. Confirm Apache is running:

$ sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

4. Check the UFW status:

$ sudo ufw status
Enter fullscreen mode Exit fullscreen mode

If UFW isn't installed, install it and allow SSH:

$ sudo apt install ufw -y && sudo ufw allow ssh
Enter fullscreen mode Exit fullscreen mode

5. Allow the Apache Full profile through the firewall to enable HTTP and HTTPS:

$ sudo ufw allow 'Apache Full'
Enter fullscreen mode Exit fullscreen mode

6. Reload UFW to apply the changes:

$ sudo ufw reload
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

2. Open the phpMyAdmin Apache configuration:

$ sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

4. Create a new .htaccess file:

$ sudo nano /usr/share/phpmyadmin/.htaccess
Enter fullscreen mode Exit fullscreen mode

5. Add the following authentication configuration to the file:

AuthType Basic
AuthName "Restricted Access to PhpMyAdmin"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

6. Troubleshoot phpMyAdmin

phpMyAdmin login fails:

$ sudo systemctl status mysql
Enter fullscreen mode Exit fullscreen mode

Double-check your MySQL username and password, and review the config file for errors:

$ sudo nano /etc/phpmyadmin/config.inc.php
Enter fullscreen mode Exit fullscreen mode

Internal Server Error:

$ sudo tail -f /var/log/apache2/error.log
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Access Denied:

$ sudo mysql
Enter fullscreen mode Exit fullscreen mode
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;
Enter fullscreen mode Exit fullscreen mode

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)