Mysql – Can’t connect from EC2 to RDS via PHP. I can directly thought

amazon ec2amazon-rdsMySQLPHP

I've set up an EC2 instance it has mysql and php-mysql installed (not mysql-server).

I've set up an RDS instance and set the security group to the EC2 instance.

I can connect via the command line from the EC2, but when I try connecting via mysqli I get the message: Can't connect to MySQL server on 'XXXX.xxxxxxx.us-east-1.rds.amazonaws.com'

This is my first time working with both.

Am I missing something here?

define("HOST", "XXXX.xxxxxxx.us-east-1.rds.amazonaws.com");
define("DBUSER", "my_user");
define("PASS", "********");
define("DB", "mydb");
define("PORT", 3306);

$link=mysqli_connect(HOST,DBUSER,PASS,DB,PORT); 

// Check connection
if (mysqli_connect_errno($link)){
    echo "Failure to connect: " . mysqli_connect_error();
}

mysqli_close($link);

Best Answer

I found a similar issue.

The solution was to run setsebool -P httpd_can_network_connect=1