'AWS php5.4 cant connect to RDS

I recently created a new SSD (t2.small) standard linux box on AWS and installed
php -v
PHP 5.4.30 (cli) (built: Jul 9 2014 21:40:37) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with

/usr/sbin/httpd -v
Server version: Apache/2.4.9 (Amazon) Server built: Apr 1 2014 05:31:18

when I
php -m | grep mysqli
it returns
mysqli

However when i try conncting to RDS, this test does not return anything, i get a spinner and it times out. Also nothing returns to php log

$mysqli = new mysqli("amazonrds", "user", "password", "database");
if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";

RDS security group is ok, i can connect using MySql Workbench.

How can i connect PHP to RDS?
thank you

fixed i had to add the public ip in the field CIDR/IP of your current machine



Solution 1:[1]

I have the same issue with EC2 which installed PHP5.

I have two servers.

servers1: PHP 7.4

From EC2 1 I run command: nc -zv rds_endpoint 3306 Result: Connection to rds_endpoint 3306 port [tcp/mysql] succeeded!

I wrote a PHP code and connect to RDS and it works fine.

servers2: PHP 5.3

From servers2 I run command: nc -zv rds_endpoint 3306 Result: Connection to rds_endpoint 3306 port [tcp/mysql] succeeded! I tried the command: mysql - h rds_endpoint -u dbuser -p dbpass. The result is a successful connection.

I wrote the same PHP code with servers1 to connect, but it can't connect to RDS.

This is the issue on aws forums. https://forums.aws.amazon.com/thread.jspa?threadID=115970

Anything any update for this case?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Trung