# 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, following MySQL database administration practices documented in [**Vultr Docs**](https://docs.vultr.com/how-to-install-phpmyadmin-on-ubuntu-24-04).

* * *

## 1\. Set Up the MySQL Database Server

**1\. Update the APT package index:**

```console
sudo apt update
```

**2\. Install MySQL server:**

```console
sudo apt install mysql-server -y
```

**3\. Log in to the MySQL server:**

```console
sudo mysql
```

**4\. Create a sample database:**

```sql
mysql> CREATE DATABASE my_company;
```

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

```sql
mysql> CREATE USER 'company_admin'@'localhost' IDENTIFIED BY 'your_password';
```

**6\. Grant the user full privileges on the database:**

```sql
mysql> GRANT ALL PRIVILEGES ON my_company.* TO 'company_admin'@'localhost';
```

**7\. Flush privileges to apply the changes:**

```sql
mysql> FLUSH PRIVILEGES;
```

**8\. Exit the MySQL console:**

```sql
mysql> EXIT;
```

## 2\. Install phpMyAdmin

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

**1\. Update the APT package index:**

```console
sudo apt update
```

**2\. Install PHP and the required extensions:**

```console
sudo apt install php php-mysql php-mbstring php-json php-xml php-curl php-zip php-common -y
```

**3\. Install phpMyAdmin:**

```console
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:**

```console
dpkg -l | awk '/phpmyadmin / {print}'
```

Output:

```plaintext
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:**

```console
sudo a2enconf phpmyadmin.conf
```

**2\. Restart Apache to apply the configuration changes:**

```console
sudo systemctl restart apache2
```

**3\. Confirm Apache is running:**

```console
sudo systemctl status apache2
```

**4\. Check the UFW status:**

```console
sudo ufw status
```

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

```console
sudo apt install ufw -y && sudo ufw allow ssh
```

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

```console
sudo ufw allow 'Apache Full'
```

**6\. Reload UFW to apply the changes:**

```console
sudo ufw reload
```

## 4\. Access phpMyAdmin

**1\. Open the phpMyAdmin endpoint in a browser using your server's IP address or domain name:**

```plaintext
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`**:**

```console
sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_username
```

**2\. Open the phpMyAdmin Apache configuration:**

```console
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:**

```apacheconf
<Directory /usr/share/phpmyadmin>
    AllowOverride All
    ...
</Directory>
```

**4\. Create a new** `.htaccess` **file:**

```console
sudo nano /usr/share/phpmyadmin/.htaccess
```

**5\. Add the following authentication configuration to the file:**

```apacheconf
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:**

```console
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:**

```plaintext
http://your_server_ip/phpmyadmin
```

## 6\. Troubleshoot phpMyAdmin

**phpMyAdmin login fails:**

```console
sudo systemctl status mysql
```

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

```console
sudo nano /etc/phpmyadmin/config.inc.php
```

**Internal Server Error:**

```console
sudo tail -f /var/log/apache2/error.log
```

Reinstall the required PHP extensions if any are missing:

```console
sudo apt install php-mysql php-mbstring php-json php-xml php-curl php-zip php-common -y
```

**Access Denied:**

```console
sudo mysql
```

```sql
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**](https://docs.vultr.com/how-to-install-phpmyadmin-on-ubuntu-24-04).
