SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘xxx.xxx.xxx.xxx’ (13)

One of the things I wish I had found in Google faster when trying to figure out why PHP script refuses to connect to remote MySQL server issuing an error
SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'xxx.xxxx.xxx.xxx' (13)

I am able to connect from local shell, so first thought was if something wrong with recent Zend Framework upgrade, but after a while I figured out that answer is very simple – SELinux was blocking remote connections from PHP scripts executed by Apache web server. The error code (13) at the end of error message means “permission denied”, so that’s the indication to see if you have similar issue or not.

Anyway, login as root and do
setsebool -P httpd_can_network_connect=1
to make it work.

Of course, think twice because you make web server a bit less secure, so don’t do that unless you are sure you need it.

9 Responses to “ “SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘xxx.xxx.xxx.xxx’ (13)”

  1. Jonathan Nieto says:

    Thanks! you saved me so much time!

  2. Sanjay Malunjkar says:

    That was exactly my problem. I would imagine that phpmyadmin talking to remote mysql will require this change.

  3. Dan Thomas says:

    Thanks very much.. spent ages trying to sort this problem out!!
    Thanks Again :)

  4. This came in handy just now. Thankfully I found your blog before I spent even more time debugging.

    Thanks again.

  5. Ashutosh says:

    Thanks a lot. Really helped and saved some time

  6. M@tt says:

    Hello
    ,
    As opposed to you, Google helped me and I found your post !
    Thanks a lot !!! You saved me a lot of troubleshooting time !!

    Cheers,
    M@tt

  7. Ganesh says:

    Thanks!! It saved me from more frustration. Upgraded from one linux version to other and started with this…..THNX

  8. Warnajith says:

    Thanx a lot It help me toooo. Thanx again

  9. varun says:

    for mac go to system preferences -> network-> sharing->web sharing on .. to enable httpd connections

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>