While MySQL prompt is used and recommended by the developer community for database administration, most people prefer a graphical user interface over the old school command line prompt. As of this writing, only a few database administrator applications are available to provide a web interface. PhpMyAdmin is the most popular for MySQL database management system.
This guide will help you to install phpMyAdmin on your ubuntu server with the best practices by the developer community.
System Requirements:
- Ubuntu 22.04 server
- A working LEMP stack installed.
If you are on a fresh Ubuntu installation, you can install LEMP stack first before continue to the guide. We will cover post-configuration for nginx web server.
Install phpMyAdmin on Ubuntu 22.04 for nginx
We will start by refreshing the package repository, then install phpmyadmin along with the php modules.
sudo apt update
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
The installation script will ask whether to use apache or lighthttpd as web server. You will need to skip selecting any web server by pressing TAB to highlight <Ok> then press ENTER to continue the installation process.
For the dbconfig-common
prompt, Select Yes to set up the database
Then you will be asked to choose and confirm a MySQL application password for phpMyAdmin.
Once the post configuration script succeed, Nginx is configured to work with phpMyAdmin. We will need to create a symbolic link from the installation files to Nginx’s document root directory.
sudo ln -s /usr/share/phpmyadmin /var/www/your_domain/phpmyadmin
To access the phpmyadmin interface, go to :
https://server_domain_or_IP/phpmyadmin
Securing phpMyAdmin on Ubuntu 22.04 for nginx
Here are a few steps you can take to secure your PHPMyAdmin installation on an Nginx server:
- Use SSL/TLS to encrypt traffic between the client and the server. This will help prevent eavesdropping and man-in-the-middle attacks.
- Restrict access to PHPMyAdmin to specific IP addresses or networks. This can be done using Nginx’s
allow
anddeny
directives. For example:
location /phpmyadmin {
allow 192.168.1.0/24;
deny all;
}
- Use HTTP authentication to require a username and password to access PHPMyAdmin. You can use Nginx’s built-in HTTP authentication module or an external authentication module like
mod_auth_basic
. - Use a different URL for PHPMyAdmin than the default. For example, instead of using
/phpmyadmin
, you could use a URL like/pma
or/database-admin
. This can make it more difficult for attackers to find your PHPMyAdmin installation. - Keep your PHPMyAdmin installation up to date. New versions of PHPMyAdmin often include security fixes and improvements, so it’s important to keep your installation up to date.
- Consider using a tool like Fail2ban to protect against brute-force login attempts. Fail2ban can monitor your server logs and block IP addresses that are making repeated failed login attempts.
By following these steps, you can help secure your PHPMyAdmin installation and protect it from potential attacks