Although a significant number of people need the features of a database management system like MySQL and MariaDB, they may not feel confident using the system just from the MySQL prompt.
The purpose of phpMyAdmin is to enable web-based interaction between users and MySQL. In order to securely manage your databases on an Ubuntu server.
This article will walk you through installing phpMyAdmin on an Ubuntu server running along with LAMP stack and securing the installation by restricting external access.
Step 1: Install phpMyAdmin
To begin, update your package list and install phpMyAdmin using the following command:
sudo apt install phpmyadmin
Step 2: Install Required PHP Libraries
phpMyAdmin requires certain PHP modules to function properly. Install them with:
sudo apt install php-mbstring php-zip php-gd php-json php-curl
- php-mbstring: A module for managing non-ASCII strings and convert strings to different encodings
- php-zip: This extension supports uploading .zip files to phpMyAdmin
- php-gd: Enables support for the GD Graphics Library
- php-json: Provides PHP with support for JSON serialization
- php-curl: Allows PHP to interact with different kinds of servers using different protocols
Step 3: Configure Apache for phpMyAdmin
Create a symbolic link to include the phpMyAdmin configuration file in Apache’s available configuration directory:
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
Step 4: Enable mbstring PHP Module
Enable the mbstring module for PHP, as it’s essential for phpMyAdmin:
sudo phpenmod mbstring
Step 5: Enable phpMyAdmin Configuration for Apache
Activate the phpMyAdmin configuration in Apache:
sudo a2enconf phpmyadmin.conf
Step 6: Restart Apache
To apply all the changes, restart the Apache server:
sudo systemctl reload apache2.service
Step 7: Access phpMyAdmin Web Interface
Open your browser and navigate to:
https://your_domain_or_IP/phpmyadmin
Replace your_domain_or_IP
with the actual domain or IP address of your server.
Securing phpMyAdmin
phpMyAdmin is an effective application, and because of its popularity, it is an appealing and frequent target for attackers, therefore you should take further measures to prevent unauthorized access. Because I won’t be administering the database from outside of my business network, I’m restricting phpmyadmin access to my local lan subnet. You should too not expose this to unauthorized users.
Edit the phpmyadmin.conf file located in your Apache configuration directory using your choice text editor. Here, I utilize nano.
Edit the Apache configuration file:
sudo nano /etc/apache2/apache2.conf
Add the following block at the end of the file:
<Directory "/usr/share/phpmyadmin">
Order Deny,Allow
Deny from all
Allow from 10.2.0.0/16
</Directory>
This configuration blocks all external traffic except for IP addresses in the 10.2.0.0/16
subnet.
Save and exit the file.
Restart Apache to apply the changes:
sudo systemctl reload apache2.service
By following these steps, you’ll have phpMyAdmin installed and secured on your Ubuntu Server to be used with your LAMP installation . Enjoy managing your databases efficiently! Using this interface, you can create databases, users, and tables, as well as perform the usual operations like deleting and modifying structures and data.
If you have any questions or run into issues, feel free to share them in the comments.