user3477706
user3477706

Reputation: 11

Connecting to RDS instance through VPC from EC2 using PHP

I've been looking on stackoverflow for quite some time, but I just can't seem to find a solution... Here's what my situation looks like:

Now here's my problem:

I can't seem to figure out how to connect to RDS from EC2 through a simple PHP script. Whenever I try to connect, I get error code 13. Since EC2 can connect through the terminal, I'm guessing that's due to being in the same subnet; however, when I try to connect through PHP (I'm assuming at this point it's trying to connect with the EIP address) I get an error.

Weird thing is a I can connect to RDS though Sequel Pro (Mac equivalent to Navicat or phpMyAdmin), but not through EC2.

I'm starting to think it's not longer a security group issue, but a OS/PHP configuration on my EC2 instance that's completely slipped my mind.

Any thoughts? Thanks in advanced!

Upvotes: 1

Views: 1649

Answers (2)

Voluminous
Voluminous

Reputation: 126

I am re-posting my answer from another thread, since yours came up as related:

What are you running on your EC2? Just asking in case it's an SELinux (Security-Enhanced Linux), in which case it could possibly be the security limitation.

At your terminal, if you run:

getsebool -a | grep httpd

you should be able to see this limitation (whether your webserver can "network" or not. If it cannot, then run this, which should fix your problem:

setsebool -P httpd_can_network_connect 1

Hope that solves it, otherwise I don't see where the issue can arise, especially since you say you can connect via terminal (so AWS security groups should not be the issue).

Upvotes: 5

Rico
Rico

Reputation: 61699

You can try to connect to your RDS instance using your internal subnet IP address. To find out which one is you internal IP address (from your VPC subnet) from your EC2 instance in the same subnet:

ping <your-rds-endpoint-without-3306>

Double check you use the right credentials.

Upvotes: 0

Related Questions