Install and Secure phpMyAdmin with LAMP Stack on Ubuntu
Introduction: phpMyAdmin is a popular web-based graphical interface used to manage MySQL and MariaDB databases. It provides a user-friendly interface for performing database management tasks, making it an essential tool for developers and administrators. In this tutorial, we will guide you through the step-by-step process of installing and securing phpMyAdmin on Ubuntu 20.04 LTS, along with the LAMP (Linux, Apache, MySQL, PHP) stack.
Table of Contents:
- Prerequisites
- Install LAMP Stack on Ubuntu 20.04
- Install phpMyAdmin
- Configure Apache for phpMyAdmin
- Secure phpMyAdmin with an SSL Certificate
- Configure Authentication and Security
- Testing and Accessing phpMyAdmin
- Conclusion
1. Prerequisites
- An Ubuntu 20.04 LTS server with a non-root user account and sudo privileges.
- A LAMP stack installed and configured on your server. If you haven’t set up LAMP, refer to the official Ubuntu documentation.
2. Install LAMP Stack on Ubuntu 20.04
If you haven’t already installed the LAMP stack on your Ubuntu server, follow these steps to set it up:
- Update the package index and install Apache:
sudo apt update
sudo apt install apache2
- Install MySQL server and follow the prompts to set the root password:
sudo apt install mysql-server
sudo mysql_secure_installation
- Install PHP and necessary modules:
sudo apt install php libapache2-mod-php php-mysql
3. Install phpMyAdmin
Now, let’s proceed with the installation of phpMyAdmin:
- Install phpMyAdmin and its dependencies:
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
- Select “apache2” using the spacebar, and press Enter to continue.
- Set a password for the phpMyAdmin application database. Choose a strong password and confirm it.
4. Configure Apache for phpMyAdmin
To configure Apache to recognize and serve phpMyAdmin, follow these steps:
- Open the Apache configuration file for phpMyAdmin in a text editor:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
- Find the line containing
Require ip 127.0.0.1
and add your server’s IP address below it. You can find your IP address by runningip a
orifconfig
commands. - Save the file and exit the text editor.
- Enable the phpMyAdmin configuration by creating a symbolic link:
sudo ln -s /etc/apache2/conf-available/phpmyadmin.conf /etc/apache2/conf-enabled/phpmyadmin.conf
- Restart Apache for the changes to take effect:
sudo systemctl restart apache2
5. Secure phpMyAdmin with an SSL Certificate
To secure the phpMyAdmin interface with an SSL certificate, follow these steps:
- Install the SSL certificate package:
sudo apt install certbot
- Obtain an SSL certificate for your domain using Certbot:
sudo certbot --apache
- Follow the prompts to generate and install the SSL certificate.
6. Configure Authentication and Security
To enhance the security of your phpMyAdmin installation, it is recommended to enable authentication and implement additional security measures. Follow these steps:
- Open the phpMyAdmin configuration file in a text editor:
sudo nano /etc/phpmyadmin/config.inc.php
- Uncomment the line containing
$cfg['Servers'][$i]['auth_type'] = 'cookie';
by removing the leading double slashes (//
). - Save the file and exit the text editor.
- Restart Apache for the changes to take effect:
sudo systemctl restart apache2
7. Testing and Accessing phpMyAdmin
To test your phpMyAdmin installation and access it through a web browser, follow these steps:
- Open URL:
https://your_domain_or_server_ip/phpmyadmin
- You will be redirected to the phpMyAdmin login page. Enter your MySQL database username and password.
- If the login is successful, you will be directed to the phpMyAdmin dashboard, where you can manage your MySQL databases and perform various tasks.
8. Conclusion
Congratulations! You have successfully installed and secured phpMyAdmin with the LAMP stack on Ubuntu 20.04 LTS. Remember to keep your server and phpMyAdmin installation up to date with the latest security patches and regularly review and implement additional security measures to protect your data.