PHP cannot connect to mysql when run inside Apache

by admin on July 30, 2010 · 1 comment

I ran into a very strange issue when Apache/PHP/MySQL.
What happend was my php code suddenly cannot connect to mysql on another machine any more. The error message is:

mysqli_connect() [function.mysqli-connect]: (HY000/2003): Can't connect to MySQL server on '218.241.156.222' (13)

The strange thing was that if I connect mySQL from command line, even run the same code by php directly from command line, it worked just fine.

After searched around, I finally found the answer. Looks like it has something to do with SELinux settings.

To fix the issue, I only need to run:

setsebool httpd_can_network_connect_db 1

Before I ran the script, the file content of /selinux/booleans/httpd_can_network_connect_db was:
0 0

After I ran the script, content changed to:
1 1

{ 1 comment… read it below or add one }

jhuenul February 8, 2012 at 3:29 pm

Gracias por compartir solucion. !!!

Saludos

Joel

Previous post:

Next post: