Welcome to our guide on setting up phpMyAdmin on Ubuntu 24.04! Efficiently managing databases is critical. phpMyAdmin is a popular open-source tool that provides a user-friendly interface to manage MySQL or MariaDB databases with ease. This tutorial is tailored for both tech enthusiasts and IT professionals, offering a simple, step-by-step process to install phpMyAdmin on your Ubuntu 24.04 system. Whether you’re a developer, database administrator, or someone managing a personal project, this guide will help you streamline your database management.
Follow each step carefully, and feel free to refer back to this guide whenever needed. Let’s get started!
Table of Contents
Prerequisites:
- An Ubuntu 24.04 VPS
- At least 2GB of RAM
- SSH root access or a system user with sudo privileges
Step 1. Update System Packages
To start, log in to your Ubuntu 24.04 VPS using SSH:
ssh root@IP_Address -p Port_number
Replace ‘IP_Address’ and ‘Port_number’ with your server’s actual IP address and SSH port number. If needed, replace ‘root’ with the username of your sudo account.
Once logged in, you must make sure that all Ubuntu OS packages installed on the server are up to date. You can do this by running the following commands:
sudo apt-get update -y && sudo apt-get upgrade -y
Step 2. Install Web Server
In this tutorial, we will use Apache as the web server, but you can also opt for Nginx if you prefer. Apache, a powerful and widely used web server, is known for its flexibility and extensive module support. It is a reliable choice for hosting websites and web applications. Use the following command to install the Apache web server:
sudo apt install apache2
Once installed, we can enable Apache to start automatically at boot time by executing the following command.
sudo systemctl enable apache2
Next, start Apache using:
sudo systemctl start apache2
If everything works as expected, you can check the status with the following command.
sudo systemctl status apache2
Here’s how the output should look:
# systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-12-03 15:37:22 CST; 18h ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 14505 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Process: 17106 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 14509 (apache2)
Tasks: 8 (limit: 4564)
Memory: 17.8M
CPU: 7.656s
CGroup: /system.slice/apache2.service
├─14509 /usr/sbin/apache2 -k start
├─17119 /usr/sbin/apache2 -k start
├─17120 /usr/sbin/apache2 -k start
├─17121 /usr/sbin/apache2 -k start
├─17122 /usr/sbin/apache2 -k start
├─17123 /usr/sbin/apache2 -k start
├─17141 /usr/sbin/apache2 -k start
└─17564 /usr/sbin/apache2 -k start
Step 3. Install MySQL
MySQL is an open-source relational database management system. Execute the following command to install MySQL on Ubuntu 24.04.
sudo apt install mysql-server
Once installed, we can enable MySQL to start automatically at boot time by executing the following command.
sudo systemctl enable mysql
Next, start MySQL using:
sudo systemctl start mysql
If everything works as expected, you can check the status with the following command.
sudo systemctl status mysql
Here’s how the output should look:
# systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-12-03 15:52:33 CST; 18h ago
Process: 14694 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 14702 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 4564)
Memory: 548.3M
CPU: 8min 45.011s
CGroup: /system.slice/mysql.service
└─14702 /usr/sbin/mysqld
Step 4. Install PHP
There are two main methods to install PHP on Ubuntu. We will use the standard approach and install PHP from the Ubuntu repositories using the APT package manager, as shown below:
sudo apt install php libapache2-mod-php php-mysql
However, it is important to note that this method does not provide the latest version of PHP. Currently, the repository only provides PHP 8.3.
Next, we will install PHP extensions with the following command:
sudo apt install php-{cli,mbstring,zip,gd,curl,json}
Step 5. Install phpMyAdmin
After installing the necessary system dependencies, you can use APT to install phpMyAdmin from the default Ubuntu repositories using the following command:
sudo apt install phpmyadmin
To configure your installation correctly, follow these prompts:
- Select apache2 as the server during the server selection step.
- Choose Yes when asked whether to use dbconfig-common to set up the database.
- Provide and confirm a MySQL application password for the phpMyAdmin database when prompted.
During the installation, the phpMyAdmin Apache configuration file is placed in the /etc/apache2/conf-enabled/ directory, where it is automatically loaded. To complete the setup of Apache and PHP for phpMyAdmin, you need to manually enable the mbstring PHP extension. This can be done by running the following command:
sudo phpenmod mbstring
Then restart the apache2 service to apply the changes:
systemctl reload apache2
Step 6. Create a MySQL User
To log in to our MySQL system we use the following command:
mysql -u root -p
By executing this command we tell the MySQL client to log us in with the root user and to prompt us for the user’s password.
Create a new MySQL user with the following query:
CREATE USER 'DatabaseUser'@'localhost' IDENTIFIED BY 'YourStrongPassword';
Ensure that you replace the value of the “YourStrongPassword” key above with a more secure password and “DatabaseUser” with your desired username.
After creating a new user, you can assign various types of privileges depending on their role and required access. MySQL offers a range of privileges, including:
ALL PRIVILEGES: Grants the user full access to all databases and tables.
SELECT: Allows the user to retrieve data from tables.
INSERT: Enables the user to add new rows to tables.
UPDATE: Permits the user to modify existing data in tables.
DELETE: Allows the user to remove rows from tables.
CREATE: Enables the user to create new databases and tables.
DROP: Grants the ability to delete databases and tables.
GRANT OPTION: Allows the user to grant or revoke privileges from other users.
Carefully assign privileges to ensure that the user has the necessary access without compromising the security of your database.
Granting permissions is typically done in this format:
GRANT <permission type> ON <database>.<table> TO '<username>'@'<host>';
For our new set of permissions to take effect we need to reload all the privileges:
FLUSH PRIVILEGES;
Finally, we can test our new user by accessing phpMyAdmin at the URL http://YOUR_SERVER_IP/phpmyadmin. You should see the following page:
Step 7. Create Virtual Host
If you want to use a domain name instead of your server’s IP address, you need to create an Apache virtual host:
sudo nano /etc/apache2/sites-available/phpmyadmin.conf
Insert the following configuration into the file:
<VirtualHost *:80>
ServerAdmin admin@mydomain.com
ServerName phpmyadmin.mydomain.com
DocumentRoot /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
# limit libapache2-mod-php to files and directories necessary by pma
<IfModule mod_php7.c>
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/usr/share/doc/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/:/usr/share/javascript/
</IfModule>
# PHP 8+
<IfModule mod_php.c>
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/usr/share/doc/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/:/usr/share/javascript/
</IfModule>
</Directory>
# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
Require all denied
</Directory>
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin_error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin_access.log combined
</VirtualHost>
Be sure to update “phpmyadmin.mydomain.com” with your domain name.
Save and close the file, then enable the site and reload the Apache2 service to apply the changes.
a2ensite phpmyadmin
systemctl reload apache2
You can now access phpMyAdmin using your domain name at http://phpmyadmin.mydomain.com and begin working on your databases. For additional details about phpMyAdmin, its features, and configuration, refer to their official documentation.
Of course, you don’t have to install phpMyAdmin on Ubuntu 24.04 if you use one of our Ubuntu VPS Hosting services, in which case you can simply ask our expert Linux admins to install and configure phpMyAdmin on Ubuntu 24.04 for you. They are available 24×7 and will take care of your request immediately.
If you liked this post on installing phpMyAdmin on Ubuntu 24.04, please share it with your friends or simply leave a comment in the comments section.