How to Install and Secure phpMyAdmin on Ubuntu
phpMyAdmin is a popular web-based application that provides an interface for managing MySQL databases. It allows users to perform various database operations through a user-friendly interface. This guide will walk you through the steps to install and secure phpMyAdmin on Ubuntu 18.04/20.04.
1. Prerequisites
Before you begin, ensure you have the following:
- A server running Ubuntu 18.04 or 20.04.
- MySQL or MariaDB installed and running.
- Apache or Nginx web server installed.
- Sudo privileges on the server.
2. Installing phpMyAdmin
Step 1: Update the Package Index
Open your terminal and update the package index:
sudo apt update
Step 2: Install phpMyAdmin
Run the following command to install phpMyAdmin:
sudo apt install phpmyadmin
During the installation, you will be prompted to choose a web server. Select Apache or Nginx depending on what you have installed.
Step 3: Configure the Database for phpMyAdmin
When prompted, select Yes to configure the database. You will also be asked to enter the MySQL application password for phpMyAdmin. If you don’t have a password set, leave it blank and press Enter.
3. Configuring Apache
If you are using Apache, you may need to enable the phpMyAdmin configuration. Run the following command:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Make sure the file includes the following lines:
Alias /phpmyadmin /usr/share/phpmyadmin <Directory /usr/share/phpmyadmin> Options Indexes FollowSymLinks DirectoryIndex index.php <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> Require all granted </RequireAny> </IfModule> </Directory>
Save and exit (CTRL + X, then Y, then Enter).
Step 4: Restart Apache
After the configuration, restart the Apache server:
sudo systemctl restart apache2
4. Securing phpMyAdmin
Step 1: Create an Apache Password File
To secure phpMyAdmin, you can set up basic authentication. First, install the apache2-utils package if you don’t have it:
sudo apt install apache2-utils
Next, create a password file using the following command:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd username
Replace username with the desired username. You will be prompted to enter and confirm a password.
Step 2: Update the phpMyAdmin Configuration
Edit the phpMyAdmin configuration file:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Add the following lines inside the <Directory /usr/share/phpmyadmin> section:
Step 3: Restart Apache Again
After making these changes, restart Apache once more:
sudo systemctl restart apache2
5. Accessing phpMyAdmin
Now you can access phpMyAdmin by navigating to:
http://your_server_ip/phpmyadmin
You will be prompted to enter both the Apache username and password you created, followed by the MySQL username and password.
6. Conclusion
Installing and securing phpMyAdmin on Ubuntu 18.04/20.04 is a straightforward process that provides a powerful interface for managing MySQL databases. By following this guide, you can ensure that your phpMyAdmin installation is not only functional but also secure against unauthorized access. Regularly monitor your phpMyAdmin usage and keep your system updated for optimal performance and security.