Can’t connect to MySQL server on… (13)

| 3 Comments

Today I spent about 4 hours battling an issue while setting up a new server. We decided to use the old server as a dedicated MySQL box (previously Apache and MySQL were hosted on the same machine). I completed all the configurations on MySQL but my PHP application was throwing a ‘Can’t connect to MySQL server on … (13)’ error. I was able to access MySQL remotely from the new server using command line, and was able to telnet to port 3306 so I knew I was able to connect. For some reason my PHP application was just unable to. Finally, I discovered that because the new server was running CentOS I needed to disable SELinux. If you’re experiencing this issue then this is a possible resolution. Alter the /etc/sysconfig/selinux file by changing the line:

SELINUX=enforcing

To

SELINUX=disabled

You’ll then need to reboot your server. Once I made this change my PHP application was able to connect to the database without any issues.