Tutorials  /  Ubuntu

Install and Secure phpMyAdmin on Ubuntu 24.04: A Comprehensive Guide

Ccentron Redaktion · March 2025 ·10 min read ·Ubuntu, Tutorial

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.
VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

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:

Console
$ sudo apt update

Install the MySQL Server

If MySQL isn't already installed, use the following command:

Console
$ sudo apt install mysql-server -y

Access the MySQL Shell

Log in to the MySQL command-line tool:

Console
$ sudo mysql

Create a Sample Database

Execute the following SQL command to make a new database named my_company:

Code
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:

Code
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:

Code
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:

Code
mysql> FLUSH PRIVILEGES;

Close the MySQL Shell

Exit the MySQL interface with this command:

Code
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:

Console
$ sudo apt update

Install PHP and Required Extensions

Install PHP along with all necessary extensions required by phpMyAdmin:

Console
$ 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:

Console
$ 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:

Console
$ dpkg -l | awk '/phpmyadmin / {print}'

Expected Output:

Code
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:

Console
$ sudo a2enconf phpmyadmin.conf

Expected Output: Conf phpmyadmin already enabled

Restart Apache Web Server

Apply the changes by restarting Apache:

Console
$ sudo systemctl restart apache2

Check Apache Server Status

Verify that Apache is up and running:

Console
$ sudo systemctl status apache2

Expected Output:

YAML
● 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:

Console
$ 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:

Console
$ 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:

Console
$ sudo ufw allow 'Apache Full'

Reload the Firewall Rules

Apply the firewall rule updates with this command:

Console
$ 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:

Console
$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_username

Edit Apache Config for phpMyAdmin

Open the Apache configuration file for phpMyAdmin using the nano editor:

Console
$ 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:

Code
<Directory /usr/share/phpmyadmin>
    AllowOverride All
    ...
</Directory>

Create the .htaccess File

Now, create a new .htaccess file in the /usr/share/phpmyadmin/ directory:

Console
$ sudo nano /usr/share/phpmyadmin/.htaccess

Insert the following configuration into the .htaccess file:

Code
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:

Console
$ 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:

Console
$ sudo systemctl status mysql

Double-check that you're using the correct MySQL username and password.

Examine the phpMyAdmin configuration file for any mistakes:

Console
$ sudo nano /etc/phpmyadmin/config.inc.php

Internal Server Error

To investigate this issue further, check Apache’s error log:

Console
$ sudo tail -f /var/log/apache2/error.log

Ensure all necessary PHP modules are installed and active:

Console
$ 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:

Console
$ sudo mysql

Create a new MySQL user with a username and password of your choice:

Code
mysql> CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';

Grant this user full privileges for all databases:

Code
mysql> GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'localhost' WITH GRANT OPTION;

Apply the changes by refreshing the MySQL permissions:

Code
mysql> FLUSH PRIVILEGES;

Exit the MySQL interface and try accessing phpMyAdmin again:

Code
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.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren