I have a really weird situation involving phpMyAdmin trying to connect to a remote DB server. Note that all machines are running CentOS 7.
Here is my current situation:
I have a mariadb 10.2 server with a 'root'@'%' login temporarily set up.
I have two web servers set up with phpMyAdmin installed (Let's call them Client1 and Client2).
I can access the mariadb server from phpMyAdmin on Client1 but not on Client2.
The phpMyAdmin server config is identical for both Client1 and Client2.
On client2 I am able to successfully access the mariadb server through the mysql command.
I set up a mariadb server on client2 and phpMyAdmin is able to login to localhost just fine.
Here is my /etc/phpMyAdmin/config.inc.php with personal info removed
$i = 0;
$i++;
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'mypass';
$cfg['Servers'][$i]['host'] = '1.2.3.4';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
Here are the errors that phpMyAdmin shows me:
#2002 - Permission denied — The server is not responding (or the local server's socket is not correctly configured)
mysqli_real_connect(): (HY000/2002): Permission denied
I have re-installed mariadb on the local client2 machine and manually set the socket value in config.inc.php but that doesn't seem to fix anything.
The following command connects just fine from the Client2 machine even though phpMyAdmin fails:
mysql -u root -h 1.2.3.4 -pmypass
I'm just not sure how to narrow my search for the issue at this point.
解决方案
Well the answer was stupid but simple, SElinux was the issue, and not on the Database server but on the client side.
On the client side you can run:
getsebool -a | grep httpd_can_network_connect_db
I got the response:
httpd_can_network_connect_db --> off
To change it you can run:
setsebool -P httpd_can_network_connect_db on
Once I had done that phpMyAdmin connected right away on a page refresh.
I had no idea that SELinux would stop outgoing connections :(