(Dec 29) New version 0.9.8-18 has been released

[GUIDE] Secure PhpMyAdmin

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Forum rules
Before creating a new topic or reply on the forum you should fill out additional fields "Os" and "Web" in your profile section.
In case of violation, the topic can be closed or response from the support will not be received.
Posts: 6
Joined: Thu Feb 25, 2016 10:18 pm

Re: [GUIDE] Secure PhpMyAdmin

Postby lemonadv » Thu Mar 03, 2016 9:17 pm

I fixed this:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !(panel.)?next2support.com
RewriteRule .* - [F]

But again if I tried to login from VestaCP link the massage appear again:

Internal Server Error

What I'm doing wrong? I what to access the phpymyadmin only from vestacp link, not from: http://next2support.com/phpmyadmin/ for example.

Posts: 21
Joined: Thu Jun 04, 2015 9:22 am

Re: [GUIDE] Secure PhpMyAdmin

Postby www.rinku31 » Fri Mar 04, 2016 7:33 am

I think it is more simple: (ubuntu 14.04)

Check this file >> /etc/phpmyadmin/config-db.php

it is:

Code: Select all

## database access settings in php format
## automatically generated from /etc/dbconfig-common/phpmyadmin.conf
## by /usr/sbin/dbconfig-generate-include
## Thu, 01 Mar 2016 08:48:52 -0500
## by default this file is managed via ucf, so you shouldn't have to
## worry about manual changes being silently discarded.  *however*,
## you'll probably also want to edit the configuration file mentioned
## above too.
$dbpass='some pass will here';

what we have to do is, login inside phpmyadmin using root and create a database phpmyadmin. and then add a new user phpmyadmin with same password some pass will here. and add this user to phpmyadmin database. Finally we have to import example/create_tables.sql table.

Logout and login again. errors gone !

Posts: 6
Joined: Thu Feb 25, 2016 10:18 pm

Re: [GUIDE] Secure PhpMyAdmin

Postby lemonadv » Fri Mar 04, 2016 9:38 pm

I already do that! But this problem appear only when I put this in my .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !(panel.)?next2support.com
RewriteRule .* - [F]

if not everything work fine! But I want to connect phpmyadmin only from VestaCP link.

Posts: 192
Joined: Sat Aug 08, 2015 3:03 am

Re: [GUIDE] Secure PhpMyAdmin

Postby pandabb » Sat Dec 10, 2016 11:16 pm

Add nameserver referral access only (you can only access phpmyadmin by clicking it from the control panel) also uses htaccess

anyone knows how to do this if using nginx-phpfpm ?

i saw one but dont know where to put my url on the code below. Can someone please add eg. if my server name is https://pong.pandabb.com

Code: Select all

location ~/([a-zA-Z0-9\.\-]*)/* {
    set $match "$1::$http_referer";
    if ($match !~* ^(.+)::http[s]*://[www]*[.]*\1.*$ ) {
        return 403;

Posts: 1
Joined: Fri Apr 07, 2017 1:02 pm

Re: [GUIDE] Secure PhpMyAdmin

Postby syedsaqib206 » Fri Apr 07, 2017 1:41 pm

All these precautions are good, but I have applied an extra security layer which is best to stop brute-forcing.

create a php function that gets user ip.
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
} else {

if you cant find the ip return false because it is not a valid user
if ip found then use geoplugin.net api to get user location via curl

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, "http://www.geoplugin.net/json.gp?ip=".$ip);
curl_setopt($ch2, CURLOPT_HEADER, 0);
$ip_data_in = curl_exec($ch2); // string

this piece of code will return json data of the user ip

"geoplugin_credit":"Some of the returned data includes GeoLite data created by MaxMind, available from <a href='http:\/\/www.maxmind.com'>http:\/\/www.maxmind.com<\/a>.",
"geoplugin_city":"Mountain View",
"geoplugin_countryName":"United States",

now you can decode the json strings into php array and get the ip location eg: city, region, country

$ip_data = json_decode($ip_data_in,true);
$ip_data = str_replace('&quot;', '"', $ip_data);
if(isset($ip_data) && !empty($ip_data['geoplugin_countryName'])) {
$user_ip = trim($ip_data['geoplugin_request']);
$city = trim($ip_data['geoplugin_city']);
$region = trim($ip_data['geoplugin_region']);
$country = trim($ip_data['geoplugin_countryName']);

return $userData=array('userIP'=>$user_ip,'userCity'=>$city,'userRegion'=>$region,'userCountry'=>$country,);
return false;
so now the actual logic starts here, normally a server owner uses it home or office internet connection, never change its ISP frequently and also not use of proxy ips to login its server. so all the time server administrator use the same location. In my case my ISP provide mostly use three locations of my country and assign it to my ip.... my country never change but cities are changed when i reboot my router.
so the point is above code will return country and city as well... you can apply these check to restrict unwanted login attempt which is as follow:-

call this function at the very first line of index.php of phpmyadmin within <?php tag
$allowed_cntry = array('United States');
$allowed_city = array('New York', 'Los Angeles', 'Chicago');
if(!in_array($user_trace['userCity'], $allowed_city) || !in_array($user_trace['userCountry'], $allowed_cntry)){
echo "Access Denied";

now the phpmyadmin will be only access in the United States within three locations 'New York', 'Los Angeles', 'Chicago'. other wise it will die the further execution of code.
as you all knows very well brute-force use script to change the ip on every attempt.
so the above code will not give them a single chance to reach at user and password fields...

if you like this method... you can use it and get tension free from brute forcing :)


Posts: 7
Joined: Tue Apr 11, 2017 9:55 am

Re: [GUIDE] Secure PhpMyAdmin

Postby soldx » Mon May 15, 2017 8:28 pm

erldcrtz wrote:Add nameserver referral access only (you can only access phpmyadmin by clicking it from the control panel) also uses htaccess
1. open /usr/share/phpMyAdmin (centos 6)
2. create .htaccess file and paste the following code below (replacing the proper domain info server1.yourdomain.com)

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_REFERER} !(server1.)?yourdomain.com
RewriteRule .* - [F]

Hi, If anyone has problems with the referer thing getting 403 ERR just change http for https


Posts: 28
Joined: Fri Feb 17, 2017 5:34 am

Re: [GUIDE] Secure PhpMyAdmin

Postby mariad » Wed May 17, 2017 7:38 am

Thanks for the mention.

Posts: 1
Joined: Thu Aug 24, 2017 12:23 pm

Re: [GUIDE] Secure PhpMyAdmin

Postby BardiaKh » Thu Aug 24, 2017 12:27 pm

erldcrtz wrote:Alternative (most recommended)

Enable SSL on phpmyadmin and access only from name server
1. create web domain using your name server (server1.myserver.com) with SSL support and nginx
2. edit /etc/httpd/conf.d/phpMyAdmin.conf (centos 6) and delete the following (see below) and save

Code: Select all

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

<Directory /usr/share/phpMyAdmin/>
   Order Deny,Allow
   Deny from All
   Allow from All

<Directory /usr/share/phpMyAdmin/scripts/>
   Order Deny,Allow
   Deny from All
   Allow from All

3. edit /home/admin/conf/web/shttpd.conf from step 1(see above) and paste the following (see below) before this line </VirtualHost> and save

Code: Select all

Alias /phpmyadmins-GENERATE-RANDOM-PASS-CODE-HERE /usr/share/phpMyAdmin

<Directory /usr/share/phpMyAdmin/>
        AllowOverride All
        Options +Includes -Indexes +ExecCGI

<Directory /usr/share/phpMyAdmin/scripts/>
        AllowOverride All
        Options +Includes -Indexes +ExecCGI

4. restart apache server
5. you may now access your phpmyadmin with SSL from only the domain name you made.

Code: Select all


After doing these steps I receive 403 error when I go to the page

Code: Select all


Can someone help me make this right?


Posts: 5
Joined: Mon Nov 16, 2015 12:54 am

Re: [GUIDE] Secure PhpMyAdmin

Postby andresgl » Thu Nov 09, 2017 9:12 am

I think this post should be updated because any of those 'tutorials' work..

Posts: 292
Joined: Tue Dec 22, 2015 2:06 pm

Re: [GUIDE] Secure PhpMyAdmin

Postby baijianpeng » Sat Dec 16, 2017 11:31 pm

erldcrtz wrote:Force SSL Connection on phpmyadmin
1. go to folder /usr/share/phpMyAdmin (centos 6)
2 create file config.inc.php and put the following code below and save

Code: Select all

<?php $cfg['ForceSSL'] = true; ?>

I tried to apply this trick. I am running VestaCP v0.98-17 on Ubuntu 16.04.3. The directory path is:


Well, I created a new file named config.inc.php and put above code into it.

Next, I tried to visit phpmyadmin with HTTP protocol, it was NOT switched to HTTPS automatically.


Return to “Web Server”

Who is online

Users browsing this forum: No registered users and 2 guests