P粉0418819242023-08-25 17:08:22
I ran into the same problem after getting a new CentOS 7 box running SELinux. I can connect to the remote MySQL database server via the command line, but Drupal (and the test PHP script) cannot connect.
The problem is ultimately caused by the SELinux security policy.
By default, the policy httpd_can_network_connect_db is disabled (meaning your web server cannot contact the remote database).
Check with the following command:
getsebool -a | grep httpd
If httpd_can_network_connect_db is Off, please enable it through the following command:
setsebool -P httpd_can_network_connect_db 1
(The -P flag makes the changes permanent, so the settings remain in effect across reboots.)