PHP Can't Connect to MySQL with Error 13 (But Command Line Can)

php can't connect to mysql with error 13 (but command line can)

setsebool -P httpd_can_network_connect=1

will also be a helpful CLI command to many people visiting this question, as to allow mysql_connet() connections from within HTTP (Apache) requests to a remote MySQL database server, ensure to enable Network Connections from httpd in SElinux usually located in /etc/selinux/config (disabled by default to prevent hackers from attacking other machines using your httpd).

PHP not connecting to Remote MySQL

Found this to be an issue with SELinux that is not allowing httpd network connections.

Executing:

setsebool -P httpd_can_network_connect=1

Solved the problem.

PHP MySQLi giving error with external connection but can connect from other sources

From the comments, we know that it fails from the command line on the client box, but works from the command line (GUI, technically) on your personal box. We also know from these comments that it's not SELinux or IPTables. Thus, it must be either:

  • system/OS level setting on the client box other than SELinux or IPTables, or
  • router/firewall between your client box and the server.

Time to break out lower level (eg, IP) tools. Or, as you discovered, contact the upstream network administrator.

In the words of a Certain Famous Detective:

Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth.



Related Topics



Leave a reply



Submit