phpMyAdmin is a popular, free and open-source web-based administration tool for managing MySQL and MariaDB databases. It provides a user-friendly web interface that allows you to perform various database operations, such as creating and dropping databases, creating and modifying tables, and managing users and permissions.
In this tutorial, we will show you how to install and configure phpMyAdmin on Ubuntu 22.04. We will assume that you have already installed MySQL or MariaDB on your system, and that you have access to a user with administrative privileges.
Installing phpMyAdmin
To install phpMyAdmin on Ubuntu, you can use the apt
package manager. First, update the package index using the following command:
sudo apt update
Then, install the phpmyadmin
package using the following command:
sudo apt install phpmyadmin
This will install the latest version of phpMyAdmin on your system.
During the installation process, you will be prompted to select the web server that you want to use with phpMyAdmin. Select Apache
from the list of available options, and then press <Enter>
to continue.
Next, you will be asked to configure the database for phpMyAdmin. Select Yes
and press <Enter>
to continue.
You will then be prompted to enter the password for the phpmyadmin
user that will be created in the database. Enter a password and press <Enter>
to continue.
After the installation is complete, you need to enable the php
and mcrypt
Apache modules, which are required by phpMyAdmin. To do this, run the following commands:
sudo a2enmod php
sudo a2enmod mcrypt
Finally, restart the Apache web server to apply the changes:
sudo systemctl restart apache2
Configuring phpMyAdmin
After installing phpMyAdmin, you need to configure it to secure the installation and to customize its settings.
First, you need to create an .htaccess
file in the phpmyadmin
directory to restrict access to the phpMyAdmin interface. To do this, create a new file called .htaccess
in the /usr/share/phpmyadmin
directory and add the following lines to the file:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
This configuration will enable basic authentication for the phpMyAdmin interface, and will require users to provide a username and password to access the interface.
Next, you need to create the .htpasswd
file that will contain the list of users who are allowed to access the phpMyAdmin interface. To do this, run the following command:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd username
Replace username
with the username that you want to use to access the phpMyAdmin interface. You will be prompted to enter a password for the user.
After creating the .htpasswd
file, you need to modify the Apache configuration to enable the .htaccess
file that you created earlier. To do this, open the /etc/apache2/conf-available/phpmyadmin.conf
file in a text editor and add the following lines to the file:
<Directory /usr/share/phpmyadmin>
AllowOverride All
</Directory>
This will enable the .htaccess
file and allow it to override the default Apache settings for the phpmyadmin
directory.
After modifying the Apache configuration, you need to restart the Apache web server to apply the changes:
sudo systemctl restart apache2
Accessing the phpMyAdmin Interface
After installing and configuring phpMyAdmin, you can access the phpMyAdmin interface by visiting the following URL in your web browser:
<http://localhost/phpmyadmin>
This will open the phpMyAdmin login page, where you can enter the username and password that you created earlier to access the interface.
After logging in, you will see the main phpMyAdmin interface, which provides a user-friendly interface for managing your MySQL or MariaDB databases.