I am new to AWS and have set up a mysql RDS instance.
I am able to connect from my laptop using MySQLWorkbench but when I try to connect with the following code from one of my servers (not an aws server) I get the following error:
Warning: mysqli::mysqli(): (HY000/2002): Connection timed out in /home/asmserverco/public_html/sms/login.php on line 28 Connection failed: Connection timed out
Here is the php connection code:
$servername = "****.us-west-2.rds.amazonaws.com";
$username = "awsasm";
$password = "****";
$dbname = "sms";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
I have set all traffic on the instance's security group to be allowed from any IP.
why can I connect from my laptop but not my web sever?
Assuming you did not modify NACLs, check that RDS allows connection to port 3306 from your server's IP. If you want to open it for all (which is not secure therefore not recommended) it should be 0.0.0.0/0.
Also, make sure 'Publicly Accessible' is set to 'yes'.