PHPMyAdmin connect to both Local and Remote Server

Add servers into, there may be two, one is under “/etc/phpmyadmin”, the other is under your web root folder. If so, update the one under your root.

//server 1 - local
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['verbose']   = 'local';
$cfg['Servers'][$i]['host']      = 'localhost';//or ip:''
$cfg['Servers'][$i]['extension'] = 'mysqli';

//server 2 - remote
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['verbose']   = 'remote';
$cfg['Servers'][$i]['host']      = '';//hostname or ip:''
// this server must allow remote clients, e.g., host 10.9.8.%
// not only in but also in the startup configuration
$cfg['Servers'][$i]['extension'] = 'mysqli';

Then, you should see the two servers shown up on the PHPMyAdmin login screen.
If you receive the error when trying to connect to remote server, then keep on reading.

To access remote mysql database, you have to enable remote access on the remote server. Check this article.

The tricky part is to open TCP port 3306 using iptables. You have to add an rule via iptables

iptables -A INPUT -i eth0 -s -p tcp --destination-port 3306 -j ACCEPT
## is client ip, where we try to connect to db server.

But you need to make sure there is no REJECT ALL rule before this new rule. For example, using command “iptables -L”, you see there is a REJECT ALL rule before the new rule we added, then the new rule will be ignored.

[root@leijinet resources]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable
ACCEPT     tcp  --             anywhere            tcp dpt:mysql

To fix this, we need to move the new rule up. I could not find the move command, so what I did was that remove the “REJECT ALL” RULE and then add it to the end. Like

### remove a rule, "6" is the index
iptables -D INPUT 6

### add a rule back
iptables -A INPUT -i eth0 -j REJECT

Some simple note here hope can help you.

Leave a Reply

Your email address will not be published. Required fields are marked *