简体   繁体   English

无法通过AWS EC2实例使用PHP连接到AWS MYSQL RDS实例

[英]Unable to connect to AWS MYSQL RDS instance using PHP via AWS EC2 Instance

Hi I am trying to connect to Amazon Web Services MYSQL RDS Instance using PHP code stored in AWS EC2 instance. 嗨,我正尝试使用存储在AWS EC2实例中的PHP代码连接到Amazon Web Services MYSQL RDS实例。 My AWS EC2 instance is connected properly and i have installed Apache, PHP and MYSQL using PuTTY SSH Client. 我的AWS EC2实例已正确连接,并且我已使用PuTTY SSH客户端安装了Apache,PHP和MYSQL。 However, when I execute my PHP code from browser, I get following error: 但是,当我从浏览器执行PHP代码时,出现以下错误:

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

Here is my PHP code: 这是我的PHP代码:

在此处输入图片说明

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. 注意:我已使用AWS MYSQL RDS实例终端节点(无端口号)作为“ DB_SERVER”,AWS MYSQL RDS实例的主用户名和主密码。 I have stored my PHP file in /var/www/html. 我已经将PHP文件存储在/ var / www / html中。

Can anyone tell me why I am unable to connect to my AWS MYSQL RDS instance via AWS EC2 instance??? 谁能告诉我为什么我无法通过AWS EC2实例连接到我的AWS MYSQL RDS实例吗???

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. 首先尝试在EC2实例上使用mysql shell连接到RDS实例,然后确保它可以正常工作-继续调试PHP代码。

Instructions for connecting to RDS can be found here - http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html 可以在此处找到有关连接RDS的说明-http: //docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html

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 验证您的AWS RDS页面中的集群端点是否已获得授权

在此处输入图片说明

Or make sure the security group used allows the connection to the cluster. 或确保使用的安全组允许连接到群集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM