How to Install phpMyAdmin on Ubuntu 24.04
phpMyAdmin is a freely available browser-based tool designed for managing MySQL databases. It delivers an intuitive graphical interface that simplifies tasks such as creating, editing, and removing databases, tables, and columns. It also allows you to administer user accounts, import and export databases, and run SQL queries. Thanks to its web interface, phpMyAdmin eliminates the need to interact with the database server via the command-line interface (CLI).
This guide walks you through the process of setting up phpMyAdmin on Ubuntu 24.04. You’ll learn how to create MySQL databases and utilize the phpMyAdmin dashboard to manage both users and databases effectively.
Requirements
Before proceeding, ensure that you:
- Have access to an Ubuntu 24.04 system using a non-root account with sudo privileges.
Installing and Configuring the MySQL Server
Carry out the following actions to install the MySQL server and prepare a test database for phpMyAdmin.
Refresh APT Package Listings
Start by updating the system’s package list:
$ sudo apt update
Install the MySQL Server
If MySQL isn’t already installed, use the following command:
$ sudo apt install mysql-server -y
Access the MySQL Shell
Log in to the MySQL command-line tool:
$ sudo mysql
Create a Sample Database
Execute the following SQL command to make a new database named my_company
:
mysql> CREATE DATABASE my_company;
Add a New User
Create a user called company_admin
and assign it a secure password. Replace your_password
with a strong password:
mysql> CREATE USER 'company_admin'@'localhost' IDENTIFIED BY 'your_password';
Assign Permissions to the User
Give company_admin
full control over the my_company
database:
mysql> GRANT ALL PRIVILEGES ON my_company.* TO 'company_admin'@'localhost';
Apply Privilege Changes
Refresh MySQL’s permission system so your new settings take effect:
mysql> FLUSH PRIVILEGES;
Close the MySQL Shell
Exit the MySQL interface with this command:
mysql> EXIT;
Installing phpMyAdmin on Ubuntu 24.04
phpMyAdmin is included in the standard Ubuntu 24.04 package repositories. The steps below show how to install it using the APT package manager.
Update Package Index
Begin by refreshing the list of available packages:
$ sudo apt update
Install PHP and Required Extensions
Install PHP along with all necessary extensions required by phpMyAdmin:
$ sudo apt install php php-mysql php-mbstring php-json php-xml php-curl php-zip php-common -y
Install phpMyAdmin
Use the following command to install phpMyAdmin:
$ sudo apt install phpmyadmin -y
Installation Prompts
During the installation process, you’ll be prompted to choose configuration options:
- For the web server configuration, press Space to select
apache2
, then hit Enter. - When asked to configure the phpMyAdmin database with
dbconfig-common
, confirm with Yes and press Enter. - Set a secure application password for phpMyAdmin and confirm it by entering it twice.
Confirm Successful Installation
Run the command below to verify that phpMyAdmin has been installed properly:
$ dpkg -l | awk '/phpmyadmin / {print}'
Expected Output:
ii phpmyadmin 4:5.2.1+dfsg-3 all MySQL web administration tool
phpMyAdmin Configuration
phpMyAdmin comes with a default Apache configuration that enables access to it via the /phpmyadmin
URL on your domain or server IP. Follow the steps below to confirm it’s enabled and start Apache.
Enable the phpMyAdmin Apache Configuration
Enable phpMyAdmin’s Apache config file using this command:
$ sudo a2enconf phpmyadmin.conf
Expected Output: Conf phpmyadmin already enabled
Restart Apache Web Server
Apply the changes by restarting Apache:
$ sudo systemctl restart apache2
Check Apache Server Status
Verify that Apache is up and running:
$ sudo systemctl status apache2
Expected Output:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Wed 2025-02-19 14:03:08 UTC; 5min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 84623 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 74567 (apache2)
Tasks: 6 (limit: 1061)
Check Firewall with UFW
Check the current firewall status:
$ sudo ufw status
Install UFW and Allow SSH Access (If Not Installed)
If UFW isn’t installed, use this command to install it and enable SSH traffic:
$ sudo apt install ufw -y && sudo ufw allow ssh
Open HTTP and HTTPS Ports for Apache
Permit web traffic through the firewall by allowing the Apache Full profile:
$ sudo ufw allow 'Apache Full'
Reload the Firewall Rules
Apply the firewall rule updates with this command:
$ sudo ufw reload
Accessing phpMyAdmin on Ubuntu 24.04
Follow these instructions to access the phpMyAdmin web interface and begin managing the my_company
database you created earlier.
Open the phpMyAdmin URL
In your web browser (such as Chrome), go to the following URL using your server’s IP or domain:
http://your_server_ip/phpmyadmin
Log In to phpMyAdmin
Use the company_admin
MySQL user account credentials you previously configured to sign in.
Verify Interface and Access the Database
Ensure that the phpMyAdmin dashboard loads correctly. From the left sidebar, click on the my_company
database to open and manage its content.
Important Security Notice
Warning: Avoid using the MySQL root account to log in to phpMyAdmin. Doing so increases the risk of accidental changes, deletions, or exposing your system to security threats. Instead, always create specific user accounts with only the required permissions. This approach offers better control and minimizes damage if unauthorized access occurs.
Securing the phpMyAdmin Endpoint
To enhance security, you can enable basic authentication for the phpMyAdmin interface. This adds a login prompt that requires a username and password before users can access the page.
Create a .htpasswd File
Generate a new .htpasswd
file with a username and password of your choice. Replace your_username
with a preferred name (e.g., smith) and follow the prompts to enter a secure password:
$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_username
Edit Apache Config for phpMyAdmin
Open the Apache configuration file for phpMyAdmin using the nano editor:
$ sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Inside the configuration file, locate the /usr/share/phpmyadmin
directory block and insert the directive AllowOverride All
inside it.
Example Directory Block:
<Directory /usr/share/phpmyadmin>
AllowOverride All
...
</Directory>
Create the .htaccess File
Now, create a new .htaccess
file in the /usr/share/phpmyadmin/
directory:
$ sudo nano /usr/share/phpmyadmin/.htaccess
Insert the following configuration into the .htaccess
file:
AuthType Basic
AuthName "Restricted Access to PhpMyAdmin"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Explanation of the .htaccess Settings
AuthType Basic
: Specifies the use of basic HTTP authentication.AuthName "Restricted Access to PhpMyAdmin"
: Sets the message displayed on the login prompt.AuthUserFile /etc/phpmyadmin/.htpasswd
: Defines the location of the file that stores usernames and encrypted passwords.Require valid-user
: Grants access only to users listed in the password file.
Restart Apache
Apply your changes by restarting the Apache server:
$ sudo systemctl restart apache2
Verify Basic Authentication
Once restarted, visit http://your_server_ip/phpmyadmin
again. You should now be prompted for a username and password before gaining access.
After successful authentication, log in using your MySQL user credentials to begin managing your databases through phpMyAdmin.
Troubleshooting phpMyAdmin on Ubuntu 24.04
If you encounter issues while using phpMyAdmin, refer to the following sections to resolve the most common problems.
Login Issues
First, make sure that the MySQL service is running:
$ sudo systemctl status mysql
Double-check that you’re using the correct MySQL username and password.
Examine the phpMyAdmin configuration file for any mistakes:
$ sudo nano /etc/phpmyadmin/config.inc.php
Internal Server Error
To investigate this issue further, check Apache’s error log:
$ sudo tail -f /var/log/apache2/error.log
Ensure all necessary PHP modules are installed and active:
$ sudo apt install php-mysql php-mbstring php-json php-xml php-curl php-zip php-common -y
Access Denied Errors
Log in to the MySQL server shell to resolve user access problems:
$ sudo mysql
Create a new MySQL user with a username and password of your choice:
mysql> CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
Grant this user full privileges for all databases:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'localhost' WITH GRANT OPTION;
Apply the changes by refreshing the MySQL permissions:
mysql> FLUSH PRIVILEGES;
Exit the MySQL interface and try accessing phpMyAdmin again:
mysql> EXIT;
Conclusion
Congratulations! You’ve successfully installed phpMyAdmin on Ubuntu 24.04. This tool offers a simple and powerful web interface for administering MySQL databases. You’re now ready to perform essential tasks such as managing databases, inserting data, running SQL queries, and generating reports. To explore advanced options and best practices, refer to the official phpMyAdmin documentation.