Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLSTATE[HY000] [2003] Can't connect to MySQL server

I am just now migrating an application from a standard dedicated server that I have onto AWS EC2. I have also moved the database (MySQL) onto Amazon RDS. Now I have an issue that I am pretty sure has to do with either PHP or Apache configuration.

On my dedicated server I can now reach the Amazon RDS database without a problem, but on the EC2-instance, using the exact same code I get this message:

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

I can reach the db-server both from Sequel Pro on my laptop, and from PHP on my other server. I tried to put in the IP-address for the MySQL db on my other server, but same error message, so I am thinking there is some configuration either in Apache or PHP that I need to do?

It is a EC2 instance running Apache and PHP on CentOS.

Suggestions as to what configuration could be blocking this connection?

like image 805
lshas Avatar asked Feb 13 '23 02:02

lshas


2 Answers

To anyone else who might have the same problem, run this in SSH, it worked for me:

setsebool -P httpd_can_network_connect=1
like image 198
lshas Avatar answered Feb 15 '23 10:02

lshas


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

For more information see. This is a 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

like image 31
WizardOfOz Avatar answered Feb 15 '23 10:02

WizardOfOz