How install and secure phpmyadmin with nginx on a ubuntu 18.04 server?

Introduction

MySQL is being wanted by many users for the functionality of a database. And it is interacting with the system solely from the MySQL command.  It is required a SQL language familiarity for line clients also. But someone is not preferred to this interface.

phpMyAdmin created so that users can interact with MySQL and it runs with a PHP development environment for an intuitive web interface. Through this article, we discuss the way of installing phpMyAdmin on top of an Nginx server and the way of configuration to increase the security of the server.

Note:

When using software like phpMyAdmin, there is an important security consideration. Because it runs on the database server. It deals with the database credentials. Arbitrary SQL queries are facilitated to users to easily execute. phpMyAdmin widely based on the PHP application. And this is a target for attack. Through this article, we informed you regarding security measurement. Then you can make a decision either the knowledge.

Prerequisites

Before you install this, you should have to fulfill the following requirements with you.

  • According to the description of the initial server setup guide for Ubuntu 18.04, the Ubuntu 18.04 server running a LEMP (Linux, Nginx, MySQL, and PHP) stack secured with of. Still, you haven’t set up your server; you can follow some guides through the searching article.
  • You have to access this server as a non-root user with sudo privileges.

Using MySQL credentials, phpMyAdmin handle authentication. It is better to install an SSL or TLS certificate. Through that, it enables encrypted traffic between server and client. If you have not available domain configured with a valid certificate then you can available article to match with your issue.

Warning

If you not available SSL or TLS certificates ha installed on your server and if you want to still continue the process, then you can consider enforcing access via SSH tunnels which will be explained in step 05 of this article.

When you fulfilled those mention requirements, Now you can go ahead to the installation process.

Step 01: Installing phpMyAdmin

AS the first step, we have to install phpMyAdmin on the LEMP. To achieve our target, we use our usual default Ubuntu repositories.

We will start with updating the server’s package index,

    $   sudo apt update

Now you have the ability to install phpMyAdmin with:

$ sudo apt install PHPMyAdmin

When you are in the installation process, it will be asked you choose the webserver. (Either Apache or Lighthttp) to configure. But there is no need to choose a server because we use the Nginx as the web server. To move to the next step, press on the tab key and click on ok.

Then it will ask you whether you use dbconfig- common for configuring the application database. Now you select the “Yes” option. Now it will set up the internal database and administrative user for PHPMyAdmin. It will be ask from you to define a new password for the PHPMyAdmin MySQL user. It is not necessary to enter a password. if you leave it blank, it will automatically create a password for PHPMyAdmin.

Now it is finished the installation. Now we have to create a symbolic link for the installation files to Nginx document for root directory, because of the Nginx web server find and serve the phpMyAdmin files correctly.

$ sudo ln -s /usr/ share/ phpmyadmin/ var/ www/ html/ phpmyadmin

Now, it is process your phpMyAdmin installation. For the access to the interface, go to your server’s domain name or public IP address followed by phpmyadmin in your web browser:

https:// server_domain_or IP/phpmyadmin

As mention before, using MySQL credentials, phpMyAdmin handles authentication. The meaning of that, to connect to database to the database via console or via an API, you should use the same user name and password.

Note: It may be discourage the logging into phpMyAdmin as the root MySQL. Through that, it represents a significant security risk. We will discuss the way of disabling the root login.

At this point, your phpMyAdmin installation should be starting to the completely functional. We have exposed our MySQL database server to the outside world through installing a web interface. phpMyAdmin is popular in the world and it have large amount of data it may provide access to, because of that, phpMyAdmin may be a common targets for a attacker. We go ahead through this article and it will discuss the different ways for increase the security of our phpMyAdmin installation.

Step 02: Changing phpMyAdmin,s default location.

Through making it harder to find, we can protect our phpMyAdmin installation. And it is the most basic way to secure the phpMyAdmin installation. Bots will scan the common path such as phpMyAdmin, pma, admin, mysql and etc. Through changing the URL phpMyAdmin interface to non standard interface, it make difficult to find for the automated scripts the phpMyAdmin installation  and attempt are may be inherit bad results for attackers.

It creates a symbolic link pointing, when we installed the phpMyAdmin. It located in the actual file application which is the user/ share/ phpMyAdmin. We have to rename the symbol link for change the interface of phpMyAdmin.

First of all we will navigate to the Nginx document root directory and will list the files which are containing it. Through that will get a better knowledge of the change we’ll make:

$   cd / var/ www/ html/
$   ls –l

Then, you will receive the output as follow.

  Output
total 8
-rw- r-- r-- 1 root root 612 Apr 8 13:30 index. nginx- debian.html
lrwxrwxrwx 1 root root  21 Apr 8 15:36 phpmyadmin -> / user/  share/ phpmyadmin

The meaning of this output is, there is a symbolic link called phpMyAdmin in this directory. If you want, you can change this link name as you want. In addition to, this will change the access URL of phpMyAdmin. It will help to obscure the endpoint from bots hardcoded to search common endpoint names.

style="font-weight:400;">It is better to select an obscures name with purpose of the endpoint. As an example, we use the “&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;nothintosee&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;” as our end point. As that, you should use the alternative name. According to that; we will rename the link as follow;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sudo mv phpmyadmin nothingtosee&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ls -l&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;After running the above commands, you’ll receive this output as follow:&amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;Output&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;total 8&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-rw-r--r-- 1 root root 612 Apr &amp;nbsp;8 13:30 index.nginx- debian.html&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lrwxrwxrwx 1 root root &amp;nbsp;21 Apr 8 15:36 nothingtosee -&amp;amp;gt; / user/ share/ phpmyadmin&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, you will go the old URL and you will get a 404 error;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;https://server_ domain_ or_ IP/ phpmyadmin&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now it is available the phpMyAdmin interface now at the new URL as soon as configured;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;https://server_ domain_ or_ IP/ nothingtosee&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Through obfuscating the real location of &amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;phpMyAdmin on the server, your phpMyAdmin installation is securing against automated scan and from attackers.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Step 03: Disabling root login&amp;lt;/b&amp;gt;&amp;lt;/h3&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;As well as regular Linux system, on MySQL is also have root account and it is a special administrative account with unrestricted access to the system. Although it is a privilege account, it inherits disadvantages being with a popular login name. With this known login it may be easy target for attackers. To minimize the risk, we can configure phpMyAdmin to reject any login attempts coming from the user root. According to that, you will get an “access denied” error and won’t be allowing to login, even you provide valid credentials.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;To configure and store phpMyAdmin setting we select the dbconfig- common. Because of that, the default configuration is currently stored in the database. With the purpose of define our custom setting; we have to create a new config. Inc. php file.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;The PHP file locates in the user/ share/ phpmyadmin for phpMyAdmin installation. But the application use the configuration file available in /etc/ phpmyadmin. Now we will create a new custom file inside the /etc/ phpmyadmin/ conf.d. We name it as pma_ secure.php:&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;sudo nano / etc/ phpmyadmin/ conf.d/ pma_ secure.php&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;There is the necessary setting for the disabling password setting in the following configuration file.( &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;AllownoPassword&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; set to &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;false) &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;and root login (&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;AllowRoot&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; set to &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;false);&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;etc/ phpmyadmin/ conf.d/ pma_secure.php&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;amp;lt;?php&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;# PhpMyAdmin Settings&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;# This should be set to a random string of at least 32 chars&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;cfg['blowfish_secret'] = '3!#&amp;lt;a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e6d6c1e6d2d3f"&amp;gt;[email&amp;nbsp;protected]&amp;lt;/a&amp;gt;(+=_4?),5XP_:U%%8\34sdfSdg43yH# {o';&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;i=0;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;i++;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cfg ['Servers'] [$i] ['auth_type'] &amp;nbsp;= 'cookie';&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cfg ['Servers'] [$i] ['AllowNoPassword'] = &amp;nbsp;false;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Icfg ['Servers'] [$i] ['AllowRoot'] = &amp;nbsp;false;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;After you done editing, you have to save the changes. For that, you can press the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;CTRL + X &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;and then press &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;Y &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;to confirm the changes and press &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;ENTER. &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, the changes will apply to automatically. Now there may be display error as &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;Access Denied&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;, if you try to reload the login page and try to log in as root.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;On your phpMyAdmin installation, it prohibited the root login. This will help you to secure your phpMyAdmin installation from attacks through trying to guess the root database password on your server. In addition to, for accessing the interface of phpMyAdmin, you can use less privileged MySQL account. It is also good security measurement.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;nbsp;&amp;lt;/p&amp;gt; &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Step 04: Creating an authentication gateway&amp;lt;/b&amp;gt;&amp;lt;/h3&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;You can avoid some automated bots through hiding your phpMyAdmin installation on unusual location. But it is not a solution for targeted attacks. It is better to protect a web application with restricted access and it generally wise protective action to stop attackers before they reach the application. Through this, attackers are unable to attacks to guess the access credentials and use generic exploits.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;It is more important to keep the login interface locked away at specific case of phpMyAdmin. You provide a chance for attackers to guess your database credentials through keeping it open to the world.&amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;You can increase security of your phpMyAdmin installation, through adding an extra layer of authentication. Before seeing the phpMyAdmin login screen, user will required to pass through an HTTP authentication prompt. Most of time, Most of web servers and Nginx also provide this capability natively.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;First of all, we should have created a password file to store the authentication credentials for set this. Nginx requires to crate the password ne encrypted through using the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;crypt ( ) &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;function. It is already included in the OpenSSL suite which you have installed on your server. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;To create an encrypted password, type as follow;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$ openssl passwd&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now it will require entering and confirming the password, which you wish to use as password. After confirming the password, it will display the encrypted version of the password. It may be as follow;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Output&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;O5az. RSPzd. HE&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;This code will be need to past into the authentication file which we will be creating. Because of that copy this value. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, we have to create an authentication file. We identify this file as &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;pma_ pass &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;and place it in the Nginx configuration directory;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;sudo nano / etc/ nginx/ pma_ pass&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;In this file, you have to specify which you like username. Now you can use follow by a colon (: ) the encryption version of your password receive from the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;openssl passwd &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;utility.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now we will rename our user as &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;Sammy&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;, so, you can use that kind of alternative username. Then it should like as follow;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;/etc/ nginx/ pma_pass&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;sammy: O5az. RSPzd. HE&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now save and close your file.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now we are going to modify the configuration file of Nginx. For that we use the configuration file, which located is /etc/ nginx/ sites-available/ example.com. For the phpMyAdmin is currently hosted, you have to select Nginx configuration file. To get started, open the file through your text editor.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$ sudo nano /etc/ nginx/ sites- available/ example.com&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, find the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;server&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; block and &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;location&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; section with it. To match with phpMyAdmin’s current path on the server, we have to create a &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;new location&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; within this block. According to this article, the location of phpMyAdmin relative to the web root is /nothingsee:&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;/etc/ nginx/ sites- available/ default&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;server {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;location / {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try_ files $uri $uri/ =404;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;location / nothingtosee {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;# Settings for phpMyAdmin will go here&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;}&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;In here we have to set up two different directives. Through &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;auth_basic &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;define the message that will be displayed on the authentication prompt and &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;auth_basic_user_files&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;, pointing to the file we just created. The configuration looks like as follow when you finish it;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/etc/ nginx/ sites- available/ default&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;server {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;location / nothingtosee {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;auth_ basic "Admin Login";&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;auth_ basic_ user_ file /etc/ nginx/ pma_ pass;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;}&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now save and close your file when you finished. You can run it to check whether configuration file is valid.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sudo nginx -t&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Then it can be see the output as follow.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Output&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;nginx: the configuration file / etc/ nginx/ nginx.conf syntax is ok&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;nginx: configuration file / etc/ nginx/ nginx.conf test is successful&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;After that you have to reload the web server to activate the authentication gate.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;sudo systemctl reload nginx&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now we have to provide the user name and password, which you set to the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;pma_ pass &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;file, for visit the phpMyAdmin URL in your web browser.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;https://server_domain_or_IP/ nothingtosee&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;After you entering the credentials, you will able to taken to the standard phpMyAdmin login page.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Note: &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;After refreshing the page does not work, then you have to clear your &amp;lt;a href="https://clearcachewiki.com/how-to-wipe-cache-partition-and-clear-data-on-android/" data-internallinksmanager029f6b8e52c="18" title="Clear Cache" target="_blank" rel="noopener"&amp;gt;cache&amp;lt;/a&amp;gt; or use a different browser, if you are already use phpMyAdmin.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;This is providing the extra layer of security. In addition to it help to keep the MySQL logs clean of spammy authentication attempts.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;h3&amp;gt;&amp;lt;b&amp;gt;Step 05: Setting up access via encrypted tunnels (Optional)&amp;lt;/b&amp;gt;&amp;lt;/h3&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Through lock down the phpMyAdmin installation to authorized hosts only, is be a reason for increase the security of phpMyAdmin installation. For the authorized hosts in your Nginx configuration file, you can &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;whitelist&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; those files. Then it automatically rejected any IP address requests which are not included in the list. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;For the some cases, it is sufficient this feature alone. But this is not the best solution and not valid for long term. Most of times, peoples are not accessing to the internet using static IP address. When you receive a new IP address from your internet provider, you should update the Nginx configuration file with your new IP address. Without updating, you are unable to access to the phpMyAdmin interface.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;There is the more robust long term another solution. For the users can access to phpMyAdmin interface by using IP based access control. But this is valid only for access through &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;authorized IP address &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;or &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;Local host via SSH tunneling. &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now we focus on the way for that. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;In addition to provide a secure channel between user and server through the using of encrypted tunnels, it is increase the security with combining IP based access control withSSH tunneling are work as to blocking access coming from the public internet. (Except for authorized IPs)&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Setting up IP bases access control on Nginx&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;We can define the corresponding location block given site based on IP based access control on Nginx, using the directives allow and deny. As a example, if want to allow only specific request which are coming from given host, Then we can include following two lines, inside the relevant location block for the site we would like to protect;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;allow hostname_ or_IP;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;deny all;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;You will be able to allow the hosts as you want. It is enough to include one allow line for each authorized host/ IP inside the respective location block for the site you’re protecting. Until it will be find a match or due to reject the all request through deny all directives, it will be evaluated in same order as they listed.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, for the requests are coming from only local host or your current IP address, Nginx will be configured to allow. For that, first of all you should know your current public IP address which your local machine is use to connect to the internet. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;There are several ways available to find that information. Because of simplicity, we will move to the get understand the service provided by ipinfo.io Otherwise you can open the URL &amp;lt;/span&amp;gt;&amp;lt;a href="https://ipinfo.io/ip"&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;https://ipinfo.io/ip&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; in your browser. If not, you can enter following command in your local machine;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;&amp;nbsp;&amp;nbsp;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;curl &amp;nbsp;&amp;lt;/b&amp;gt;&amp;lt;a href="https://ipinfo.io/ip"&amp;gt;&amp;lt;b&amp;gt;https://ipinfo.io/ip&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Then you can get an IP address as follow;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Output&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;203.0.113.111&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Above output is your current public IP address. We can configure the phpMyAdmin’s location block, for only approve the request, which are coming from your local host and that IP address. For that, we have to edit the configuration block for phpMyAdmin inside the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;etc/ nginx/ sites-available/ example.com.&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, using your command line editor of your choice, open the Nginx configuration line. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;sudo nano / etc/ nginx/ sites-available/ example.com&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;It is already have an access rule in our current configuration. Through using the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;Satisfy all &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;directives, we can combine it the IP based access control. For the increase security, we can keep the current HTTP authentication prompt. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;After configuration of your phpMyAdmin, it will be display as follow:&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;etc/ nginx/ sites-available/ example.com&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;server {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;location / nothingtosee {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;satisfy all; #requires both conditions&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;allow 203.0.113.111; #allow your IP&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;allow 127.0.0.1; #allow localhost via SSH tunnels&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;deny all; #deny all other sources&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;auth_basic "Admin Login";&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;auth_basic_user_file / etc/ nginx/ &amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;..6pma_pass;&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;}&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, keep in mind to replace the &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;nothingtosee &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;with the actual path which phpMyAdmin can be found, and highlight the IP address with your current public IP address. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;When you finished he process, you can save and close the file. And you can run it to check whether configuration file is valid.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;$ sudo nginx –t&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Then the output may be as follow;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Output&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;nginx: the configuration file / etc/ nginx/ nginx.conf syntax is ok&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;nginx: configuration file / etc/ nginx/ nginx.conf test is successful&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, when you open the web server, it will change through above affects;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;&amp;nbsp;sudo systemctl reload nginx&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;It should not disturb to access for your IP address because of it clearly listed as an authorized host. When others are trying to access your phpMyAdmin installation, they will receive a 403 error message (Forbidden).&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;a href="https://server_domain_or_ip/nothingtosee"&amp;gt;&amp;lt;b&amp;gt;https://server_domain_or_IP/nothingtosee&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Next we move to the usage of SSH tunneling to access the web server through local request. Through this way, if your IP address will be changed, you will be able to access to the interface of phpMyAdmin. &amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Accessing phpMyAdmin through an encrypted tunnel&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;SSH tunnel work as to way of redirecting network traffic through encrypted channels. You can set a secure tunnel between your local machine and the server, through running as SSH command similar to what you would use to login into server. Now it can redirect through the encrypted tunnel the all traffic coming in on a given local port. And also can use the remote server as proxy before reaching out to the internet. When use VPN (Virtual Private Network), there also happen same procedure. But VPN is simple than set up SSH tunnels.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;We will use SSH tunneling to proxy our request to the remote web server running phpMyAdmin. You can redirect the local requests to the remote web server, through creating a tunnel between your local machine and the server where phpMyAdmin installed. More important thing of thing behind that, traffic will be encrypted and the request will reach as coming from local host to the Nginx. Through this, you can access to the phpMyAdmin interface as securely, without any matter regarding the IP address which you use. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;This is the best security method, if you cannot install SSL or TSL certificate on the web server running phpMyAdmin, because the traffic between your local machine and the remote web server will be encrypted. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;You can run the following command in your local machine for access to phpMyAdmin.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;$ &amp;nbsp;&amp;nbsp;ssh &amp;lt;a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcc9cfd9cefccfd9cecad9ce"&amp;gt;[email&amp;nbsp;protected]&amp;lt;/a&amp;gt;_domain_or_IP -L 8000: localhost:80 -L 8443:localhost:443 – N&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Let’s examine each part of the command:&amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;user: SSH user to connect to the server where phpMyAdmin is running&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;hostname_or_IP: SSH host where phpMyAdmin is running&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;-L 8000: localhost: 80 redirect HTTP traffic on port 8000&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;-L 8443: localhost: 443 redirect HTTPS traffic on port 8443&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;-N: do not execute remote commands&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Note: &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;&amp;nbsp;This command can be block the terminal till interrupted with a &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;CTRL + C. &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;In such a situation, it will be a reason for disconnect the SSH connection and packet redirection. You will be able to use the SSH option –f, if you want run this command in background mode.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now, you have to go your browser and replace &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;server_domain_or_IP&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; with &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;localhost:PORT,&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; where &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;PORT&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; is either &amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;8000&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; for HTTP or &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;8443&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; for HTTPS:&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;http://localhost:8000/ nothingtosee&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;a href="https://localhost:443/nothingtosee"&amp;gt;&amp;lt;b&amp;gt;https://localhost:443/nothingtosee&amp;lt;/b&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Note: &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;You well receive a alert message questioning the security of the SSL certificate, if you use https for accessing to the phpMyAdmin. This happens due to the mismatch with the domain name, which you use (local host) and the address registered within the certificate. (damain where phpMyAdmin is actually being served) Actually, this is a safe to proceed.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Now it being to redirect through a secure tunnel to your remote phpMyAdmin application, all request on &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;local host: 8000&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; (HTTP) and &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;local host: 8443&amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt; (HTTPS). You can increase security of your phpMyAdmin through disabling public access to your phpMyAdmin. In addition to it help to protect all traffic between your local computer and the remote server, through using encrypted tunnel to send and receive data. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;If you want to enable the access of usage of SSH tunnel for anyone to your phpMyAdmin interface (including you). For that you can remove any authorized IPs from the Nginx configuration file, for that leaving &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;127.0.0.1 &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;as the only allowed host to access that location. It is safety action to remove HTTP authentication in order to simplify your set up, when consider nobody will be able to make direct request to phpMyAdmin. In such a situation your configuration file appearance as follow;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/etc/ nginx/ sites-available/ example.com&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;server {&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;location / nothingtosee { &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;allow 127.0.0.1; #allow localhost only&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;deny all; #deny all other sources&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;. . .&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;}&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;After you reload the Nginx’s configuration &amp;lt;/span&amp;gt;&amp;lt;b&amp;gt;sudo systemctl reload nginx. &amp;lt;/b&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;You want to use the SSH tunnels to access the interface of phpMyAdmin via redirect request, because your phpMyAdmin installation will be locked down.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Conclusion&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Through this article, we discuss about the way of install phpMyAdmin on Ubuntu 18.04 running Nginx as the web server. This article covered the way of secure a phpMyAdmin installation such as disabling root login, create an extra layer of authentication, and use the SSH tunneling to access a phpMyAdmin installation via local request only.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;span style="font-weight:400"&amp;gt;Through this article, you will be able to secure your MySQL database from a reasonably secure web interface. So we hope this article will be a help for you to secure your phpMyAdmin database.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;&amp;nbsp;&amp;nbsp;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt; &amp;lt;div class="quads-location quads-ad18611 " id="quads-ad18611" style="float:none;text-align:center;padding:0px 0 0px 0"&amp;gt; &amp;lt;script data-cfasync="false"&amp;gt;&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"&gt; <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-3680998947648633" data-ad-slot="3296425561"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({});

How Install and secure phpMyAdmin with Nginx on a Ubuntu 16.04 Server?

Introduction..
Prerequisites..
Step 1 — Installing phpMyAdmin..
Step 2 — Changing phpMyAdmin's Default Location..
Step 3 — Disabling Root Login..
Step 4 — Creating an Authentication Gateway..
Step 5 — Setting Up Access via Encrypted Tunnels..
Setting Up IP-Based Access Control on Nginx..

Can I use phpMyAdmin with Nginx?

You will be able to access your MySQL or MariaDB databases in phpMyAdmin with Nginx through a graphical web interface easily, running alongside a PHP development environment. In this guide, we are going to describe steps how to install and secure PhpMyAdmin with Nginx on Ubuntu 20.04.

How do I completely install phpMyAdmin on Ubuntu?

How to Install phpMyAdmin – Ubuntu 18.04 and 20.04.
Install phpMyAdmin package..
Setup user and grant permissions..
Access phpMyAdmin on browser..
Create a new user..
Secure phpMyAdmin..

How configure PHP Nginx ubuntu?

How to setup Nginx, PHP and PHP-FPM.
Perform an apt-get update to ensure access to the latest packages..
Install Nginx on Ubuntu..
Install the php-fpm for Nginx package..
Edit the server's default config file to support PHP in Nginx..
Restart the PHP configured Nginx server..
Add a PHP file to Nginx's html directory..