SQLSTATE [HY000] [2003] Unable to connect to MySQL server

Now I am moving the application from the standard dedicated server that I have on AWS EC2. I also migrated the database (MySQL) to Amazon RDS. Now I have a problem that I'm sure this is related to setting up PHP or Apache.

On my dedicated server, I can now easily get the Amazon RDS database, but in the EC2 instance, using the same code, I get this message:

SQLSTATE[HY000] [2003] Can't connect to MySQL server on ....................eu-west-1.rds.amazonaws.com

I can get to the db server both from Sequel Pro on my laptop, and from PHP on my other server. I tried putting the IP address for the MySQL database on another server, but the same error message, so I think there is some kind of configuration in Apache or PHP that I need to do?

This is an instance of EC2 with Apache and PHP on CentOS.

Suggestions on which configuration might block this connection?

+4
source share
2 answers

For anyone who might have the same problem, run this on SSH, this worked for me:

setsebool -P httpd_can_network_connect=1
+5
source

I tried setsebool -P httpd_can_network_connect = 1 on the RHEL image on EC2 successfully, and it was able to connect with AWS-RDS in the same VPC.

For more details see. It MUST step on RHEL.

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Booleans-Configuring_Booleans.html

+2
source

All Articles