简体   繁体   中英

AWS access RDS in VPC from PHP

I am on AWS with a lamp stack connecting to RDS .
I am able to connect from MySQL Workbench using SSH to RDS through amazons security groups.
But ... now that i need to connect from the outside world using PHP , I seem to be having some issues.

Normally i would connect to RDS using sqli like this:

$dbName = "mydb.xxxxxxxxxx.us-xxxx-1.rds.amazonaws.com";
$dbTable = "mytable";
$dbUser = "myusername";
$dbPass = "xxxxxxx";

But since the new instance is on a VPC on RDS public accessibility is not available.

I changed $dbName = 'xx.xxx.xx.xxx:3306' which is the public ip of my EC2 instance, but i get an error: mysqli_real_connect(): (HY000/2005): Unknown MySQL server host 'xx.xxx.xx.xxx:3306'

I am following this guide but seem to be unsuccessful at connecting.

I think I am not doing this part correctly

Create a second VPC security group (for example, "sg-dbsrv1") and create a new rule by specifying the VPC security group you created in step 1 ("sg-appsrv1") as the source.

Any help would be very appreciated, thank you.

In the AWS console you have to either append your IP to the existing security group or create another security group with your IP and add that group to your instance.

RDS instances are not accessible except by hostname (especially if you're running Multi-AZ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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