The phpMyAdmin is an open source web application written in PHP that is used to administer and manage MySQL databases. It provides a graphical user interface that allows users to create, modify and drop databases, tables, fields and records, as well as execute SQL queries and perform other database management tasks.
To install and secure phpMyAdmin on Ubuntu 22.04, follow the steps below:
Before starting, it is important to ensure that you have upgraded to Ubuntu 22.04. To do this, open a terminal and type the following command:
sudo apt-get update && sudo apt-get upgrade
To use phpMyAdmin you will need to install an Apache web server, a MySQL database and the PHP programming language. To install these packages, type the following command in the terminal:
sudo apt-get install apache2 mysql-server php
Next, we need to change/set a new root password for the mysql server.
To change the MySQL root password on Ubuntu 22.04, follow these steps:
Open a terminal on your Ubuntu system. Log in to MySQL as root user by executing the following command and press enter:
sudo mysql -u root -p
Once you are logged in to MySQL, switch to the “mysql” database by running the following command
You can change the root password by running the following command. Replace
<new-password> with the new password you want to set:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'new-password.';
If you want to change the root password for a host other than localhost, change the query to use the correct host instead of 'localhost'. Then run the following command to apply the changes and reload the privileges:
You can exit the MySQL console by running:
Once you have done this, you can increase the security of your DB server by using the following command:
This command performs a number of basic security settings on MySQL to protect it from potential threats.
Now, you need to install phpMyAdmin on the server. To do this, type the following command in the terminal:
sudo apt-get install phpmyadmin
During the installation, you will be asked to configure some options. Select
apache2 as the web server and
Yes when asked if you want to configure the phpMyAdmin database with
Now you need to configure Apache for phpMyAdmin to work properly. In a terminal, type the following command:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
This will open the Apache configuration file for phpMyAdmin. Inside this file, add the following lines just below the line starting with
<Directory /usr/share/phpmyadmin> AddDefaultCharset UTF-8 <IfModule mod_authz_core.c> # Apache 2.4 Require ip 127.0.0.1 Require ip ::1 </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory>
Once you have added these lines, you need to save and close the file.
Type the following command in the terminal:
sudo a2enconf phpmyadmin
This will enable the phpMyAdmin configuration in Apache.
To apply the changes to Apache, it is necessary to restart the web server. Type the following command in the terminal:
sudo systemctl restart apache2
By default, phpMyAdmin is not password protected, which means that anyone with access to the phpMyAdmin URL can access the database. To password protect phpMyAdmin, follow the steps below:
sudo htpasswd -c /etc/apache2/.htpasswd <username>
<username> is the username you wish to use to access phpMyAdmin.
sudo nano /etc/phpmyadmin/apache.conf
Within this file, add the following lines just below the line starting with
<Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> Require ip 127.0.0.1 Require ip ::1 AuthType Basic AuthName "Restricted Content" AuthUserFile /etc/apache2/.htpasswd Require valid-user </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 AuthType Basic AuthName "Restricted Content" AuthUserFile /etc/apache2/.htpasswd Require valid-user </IfModule> </Directory>
After adding these lines, you must save and close the file.
sudo systemctl restart apache2
You can now access phpMyAdmin by entering the URL "http://localhost/phpmyadmin" in your web browser. You will be prompted to enter the username and password you created in the previous step to access phpMyAdmin.
success With these steps you have installed and protected phpMyAdmin on Ubuntu 22.04. It is important to remember that phpMyAdmin is a powerful tool and that incorrect configuration can compromise the security of your server and database, so it is recommended that you use it with care and always make sure you have the latest updates and security patches installed.