How to install and secure phpMyAdmin on Ubuntu 16.04

Introduction

Although many users need the functions of a database management system like MySQL, they may not only interact with the system through MySQL prompts.

PhpMyAdmin was created so that users can interact with MySQL through the web interface. In this guide, we will discuss how to install and secure phpMyAdmin so that you can safely use it to manage databases from Ubuntu 16.04 systems.

Preparation

Before you start using this guide, you need to complete some basic steps.

An Ubuntu** server** with a non-root account that can use the sudo command has been set up, and the firewall has been turned on. Students who don’t have a server can buy it from here, but I personally recommend you to use the free Tencent Cloud Developer Lab for experimentation, and then buy server.

We also assume that you have completed the LAMP (Linux, Apache, MySQL and PHP) installation on the Ubuntu 16.04 server.

Finally, there are some important security considerations when using software like phpMyAdmin, because it:

For these reasons, and because it is a widely deployed PHP application that often targets attacks, phpMyAdmin should not be run on a remote system via a normal HTTP connection. If you have a domain name, the easiest way to protect your website is to use Tencent Cloud SSL Certificate Service, which provides free trusted certificates. [Tencent Cloud SSL Certificate Installation and Operation Guide] (https://cloud.tencent.com/document/product/400/6814?from=10680) for setting. If you don't have a domain name, it is recommended that you go here first register a domain name. If you only use this configuration for testing or personal use, you can use a self-signed certificate without purchasing a domain name. The self-signed certificate provides the same type of encryption, but there is no domain name verification announcement. For self-signed certificates, you can refer to the two articles Create a self-signed SSL certificate for Apache and How to create a self-signed SSL certificate for Nginx.

After completing these steps, you can start using this guide.

Step one-install phpMyAdmin

First, we will install phpMyAdmin from the default Ubuntu repository.

We can do this by updating the local package index and then using the apt packaging system to drop down the files and install them on our system:

sudo apt-get update
sudo apt-get install phpmyadmin php-mbstring php-gettext

This will ask you some questions in order to properly configure your installation.

**Warning: When the first prompt appears, apache2 will be highlighted, but ** will not be selected. If you did not press the Space key to select Apache, the installer will not move the necessary files during the installation. Hit Space, tab, then Enter, select Apache.

The installation process actually adds the phpMyAdmin Apache configuration file to the /etc/apache2/conf-enabled/ directory and automatically reads the directory.

The only thing we need to do is to explicitly enable the PHP mcrypt and mbstring extensions, which we can execute by entering the following command:

sudo phpenmod mcrypt
sudo phpenmod mbstring

After that, you need to restart Apache to recognize your changes:

sudo systemctl restart apache2

You can now access the web interface by accessing the server's domain name or the public IP address ending in /phpmyadmin, and then do the following:

https://domain_name_or_IP/phpmyadmin

You can now log in to the interface using the root username and administrative password set during the MySQL installation.

When you log in, you will see the user interface as shown below:

Step 2-Protect your phpMyAdmin instance

We can easily start and run the phpMyAdmin interface. However, we are not done yet. Because of its ubiquity, phpMyAdmin is a popular target for attackers. We should take additional measures to prevent unauthorized access.

One of the easiest ways is to put the gateway in front of the entire application. We can use Apache's built-in .htaccess authentication and authorization functions to achieve this.

Configure Apache to allow .htaccess override

First, we need to enable .htaccess file override by editing the Apache configuration file.

We will edit the link file that has been placed in the Apache configuration directory:

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

We need in the configuration file<Directory /usr/share/phpmyadmin> Add an AllowOverride All directive to the `section, as shown below:

< Directory /usr/share/phpmyadmin>
 Options FollowSymLinks
 DirectoryIndex index.php
 AllowOverride All
    ...

After adding this line, save and close the file.

To implement the changes you made, restart Apache:

sudo systemctl restart apache2

Create .htaccess file

Now that our application has enabled .htaccess, we need to create one to actually implement some security.

In order for it to succeed, the file must be created in the application directory. We can create the necessary file and open it in our text editor with root privileges by typing:

sudo nano /usr/share/phpmyadmin/.htaccess

In this file, we need to enter the following information:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Let's review the meaning of these lines:

When finished, save and close the file.

Create .htpasswd file for authentication

The location we chose for the password file is "/etc/phpmyadmin/.htpasswd". We can now create this file and use the htpasswd utility to pass the initial user to it:

sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

You will be prompted to select and confirm a password for the user you are creating. Then, create a file with the hashed password you entered.

If you want to enter other users, you need to do this without the **-c flag **, as shown below:

sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser

Now, when you visit the phpMyAdmin subdirectory, you will be prompted to enter the other account name and password you just configured:

https://domain_name_or_IP/phpmyadmin

After entering Apache authentication, you will enter the regular phpMyAdmin authentication page to enter other credentials. This will add an extra layer of security because phpMyAdmin has been vulnerable to vulnerabilities in the past.

in conclusion

You should now have phpMyAdmin configured and ready to be used on your Ubuntu 16.04 server. Using this interface, you can easily create databases, users, tables, etc., and perform routine operations such as deleting and modifying structures and data.

For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.

Reference: "How To Install and Secure phpMyAdmin on Ubuntu 16.04"

Recommended Posts

How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure NATS on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and configure Ansible on Ubuntu 18.04
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
How to install and configure phpMyAdmin on CentOS 6
How to install and configure AppScale on Ubuntu 12.04
How to install and use Docker on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install Go on Ubuntu 20.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04