phpMyAdmin is a free and open source administration tool for MySQL and MariaDB. As a portable web application written primarily in PHP, it has become one of the most popular MySQL administration tools, especially for web hosting services.
We are assuming you already have installed the MySQL server on Ubuntu system. So just install the other required packages to run and access phpMyAdmin.
sudo apt install apache2 wget unzip
sudo apt install php php-zip php-json php-mbstring php-mysql
Once the installation is finished, enable and start the Apache web server.
sudo systemctl enable apache2
sudo systemctl start apache2
You can quickly install the phpMyAdmin from the default Ubuntu repositories. But they contain an older version of phpMyAdmin. If you are okay with the old version simply type apt install phpmyadmin, but to install the latest version, you need to download it from the official website.
Your system is ready for the phpMyAdmin installation. Download the latest phpMyAdmin archive from the official download page, or use the below commands to download phpMyAdmin 5.2 on your system. Once the downloading is finished, extract the archive and move it to the proper location.
wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip
unzip phpMyAdmin-5.2.0-all-languages.zip
sudo mv phpMyAdmin-5.2.0-all-languages /usr/share/phpmyadmin
Next, create tmp directory and set the proper permissions. This is a necessary step to make it work properly.
sudo mkdir /usr/share/phpmyadmin/tmp
sudo chown -R www-data:www-data /usr/share/phpmyadmin
sudo chmod 777 /usr/share/phpmyadmin/tmp
Now, you need to configure the webserver to serve phpMyAdmin on the network. Create an Apache configuration file for phpMyAdmin and edit it in a text editor:
sudo vim /etc/apache2/conf-available/phpmyadmin.conf
add the below content to the file.
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
<RequireAny>
Require all granted
</RequireAny>
</IfModule>
</Directory>
<Directory /usr/share/phpmyadmin/setup/>
Save your file. Press ESC key to switch to command more. Then type :wq (colon+w+q) and hit Enter button.
After making all the changes, make sure to start the Apache service to reload all settings.
sudo a2enconf phpmyadmin
sudo systemctl restart apache2
Step 4 – Adjusting FirewallD
The systems with enabled firewalls need to allow HTTP service from the firewall. Run the below commands to open a port for the webserver in the firewall.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
Connect to the MySQL server running on your system.
mysql
Execute the following MySQL queries one by one to create a database and user. Also, assign the privileges to the user on the database.
mysql> CREATE DATABASE tecadmin;
Query OK, 1 row affected (0.01 sec)
mysql> CREATE USER 'tecadmin'@'localhost' IDENTIFIED BY 'Pa$$w0rd';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL ON tecadmin.* TO 'tecadmin'@'localhost';
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
....
Step 6 – Access phpMyAdmin
All done. You have finished the setup with the phpMyAdmin on the Ubuntu Linux system. Now access phpMyAdmin with the server IP address or domain name.
http://your-server-ip-domain/phpmyadmin
Replace your-server-ip-domain with the localhost (for the local machines), or system IP address for remote machines. I have updated our DNS and pointed dbhost.tecadmin.net to the server’s IP address.
To uninstall phpMyAdmin in Ubuntu, open the terminal and run the following set of commands:
sudo apt-get remove phpmyadmin
sudo apt-get purge phpmyadmin
sudo apt-get autoremove
The "apt-get remove phpmyadmin" command will uninstall the phpmyadmin package, the purge command will remove configuration files related to Ubuntu phpMyAdmin and the autoremove command will uninstall all the dependency packages that are no longer required.
If you want to reinstall phpMyAdmin on Ubuntu, run:
sudo apt-get update
sudo apt-get install phpmyadmin
If you just want to disable access to the phpMyadmin, you could simply disable the phpMyAdmin without uninstalling it.
sudo a2disconf phpmyadmin
sudo systemctl reload apache2
To re enable phpMyAdmin, run:
You can find Ubuntu Apache phpMyAdmin configuration file under the /etc/apache2/conf-available/phpmyadmin.conf.