0
votes

Hi I am trying to connect to Amazon Web Services MYSQL RDS Instance using PHP code stored in AWS EC2 instance. My AWS EC2 instance is connected properly and i have installed Apache, PHP and MYSQL using PuTTY SSH Client. However, when I execute my PHP code from browser, I get following error:

ec2-.....compute.amazonaws.com (EC2 Public DNS) is currently unable to handle this request.
HTTP ERROR 500

Here is my PHP code:

enter image description here

NOTE: I have used AWS MYSQL RDS instance endpoint(without port number) as "DB_SERVER", master username and master password of AWS MYSQL RDS instance. I have stored my PHP file in /var/www/html.

Can anyone tell me why I am unable to connect to my AWS MYSQL RDS instance via AWS EC2 instance???

2
This type of issues is alot easier to debug if you separate the different components that could be at fault here. First try to connect to the RDS instance using a mysql shell on the EC2 instance, and after you make sure it works - proceed to debug your PHP code.Yaron Idan
Thanks for the suggestion. Can you pls post sample code to "connect to RDS instance using a mysql shell on the EC2 instance". I am new to this arena. @YaronIdanVaibhav Agarwal
It's described pretty thoroughly here - docs.aws.amazon.com/AmazonRDS/latest/UserGuide/…Yaron Idan
Also, make sure that your security groups actually grant the application access to the database.Karl Laurentius Roos
okay thanks. Will try doing that and reply. @YaronIdanVaibhav Agarwal

2 Answers

2
votes

This type of issues is alot easier to debug if you separate the different components that could be at fault here. First try to connect to the RDS instance using a mysql shell on the EC2 instance, and after you make sure it works - proceed to debug your PHP code.

Instructions for connecting to RDS can be found here - http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html

1
votes

I would start by testing the connection on the command line:

mysql -h *cluster end point* -P 3306 -u *username* -p *password*

Verify that the cluster end point in your AWS RDS page is authorized

enter image description here

Or make sure the security group used allows the connection to the cluster.