Skip to content


Can’t connect to MySQL on localhost using PHP on CentOS

This is an issue i’ve seen a couple of times over the past month:

Can’t connect to MySQL server on ’127.0.0.1′ (13)

So you’ve checked your server, MySQL is running and you’ve checked your credentials, they’re all valid yet you still can’t connect to your database.

Don’t Panic!

There is actually a very simple explanation and “SELinux”. For some reason, which i won’t want to go into, this blocks your PHP script from connecting to the MySQL server. But how do you stop this behaviour?

Simples! Login to your server and at the prompt do this:

  1. Edit /etc/sysconfig/selinux and set SELINUX=permissive
  2. (You will need to be root for this step):
    echo 0 >/selinux/enforce

Posted in Daily, Facts, Hints and Tips, Guides.

Tagged with , , , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.