PHP can not connect RDS MySQL on an Amazon EC2 RHEL box

So I decided to use Amazon RDS for my blog. It’s fairly simple to set up RDS, but somehow I couldn’t get PHP to connect to RDS. WordPress kept throwing this error: “Error establishing a database connection”.

So I thought maybe my RDS security group settings are not correct? I opened the RDS instance to and I was able to connect using mysql cli anywhere, including the RHEL box, but WP still gave me the same error. I then tried php mysql connection to RDS on another linux box and it worked!

OK, so that means somehow php mysql connection is not working on the RHEL box, what can be causing the problem? After a few Google searches, one post drew my attention, SELinux!! Of course!! How did I forget this thing…

So I went to /etc/selinux/config and set SELinux = disabled, after reboot, problem solved!

Of course you can add an exception rule but to avoid future headaches, better leave it disabled.

Leave a Reply

Your email address will not be published.