0

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???

7
  • 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. Commented Jul 21, 2016 at 8:53
  • 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. @YaronIdan Commented Jul 21, 2016 at 9:02
  • It's described pretty thoroughly here - docs.aws.amazon.com/AmazonRDS/latest/UserGuide/… Commented Jul 21, 2016 at 9:28
  • Also, make sure that your security groups actually grant the application access to the database. Commented Jul 21, 2016 at 9:47
  • okay thanks. Will try doing that and reply. @YaronIdan Commented Jul 21, 2016 at 10:08

2 Answers 2

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.

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.