Amazon RDS timeout with php pdf - php

I'm having a bit of an issue with connecting to my Amamzon RDS (Mysql) instance through a fresh Lumen installation on an Amazon EC2 instance.
The Lumen installation uses the PDO class.
The problem:
I can't connect to my RDS, I'm simply getting a timeout when trying:
SQLSTATE[HY000] [2002] Connection timed out
What have i tried?
I've tried connecting directly to the ip of my rds instance. Same result.
When debugging my connection, I get a connection string like mysql:host=x.x.x.x;port=3306;dbname=(...) - ip and db are correct. Username and password are also correct when debugging the connection.
Connecting from another server, that is outside Amazon AWS. Also using PDO = negative result
Checking that the RDS is set up to available from the outside = It is, I can connect from my own computer. Tested with two different machines.
Looking through various posts about rds and timeouts = no usable solutions
Connected directly to the ip of my RDS instance = negative result
When developing on my local machine, I'm not having any problems connecting to the same rds.
Anything else you should know?
When connecting from my computers (using Sequel Pro), i can connect - I've tried from two computers, both with positive result. This is indifferent if i use the domain/endpoint of the rds instance or connect directly to the ip.
By my own logic, I should be ablet to connect from any EC2 instance, since I can connect from my own computer.
Any help would be appriciated.

Did you actually give the right permission inbound to RDS from that EC2 Instance?
You need to modify your security group to give access.

Related

Connection refused when trying to connect to AWS RDS

I'm thinking about moving (parts of) my MySQL databases to AWS RDS. They are now running on the same dedicated server as my PHP website but I want to change that for scaling purposes.
So I'm playing around with AWS RDS (I'm new to it). I've setup a MySQL database and can connect to it using MySQL Workbench.
The problem is that I can't let my PHP scripts (which are running on a different dedicated Linux server) connect to it using
new mysqli('***.***.***.rds.amazonaws.com', 'user', 'pass', 'db_name',3306);
I double checked on AWS:
... that the DB is Available
... the port is 3306
... that public accessibility is set to
'yes'
... that both inbound and outbound rules for the security group
are set to All traffic - 0.0.0.0/0 and All traffic - ::/0
and still PHP is giving me: mysqli::__construct(): (HY000/2002): Connection refused
What am I missing here? Should I change something on the dedicated server too? Note that I'm using the Free tier in AWS while doing these tests.

AWS, ec2 and RDS mysqli::real_connect(): Connection timed out

I have set Ec2 Linux server with only PHP is installed in it not mysql.
I have separately configured RDS
Installed workbench and logged in using endpoint of RDS and username and password
In workbench DB connection done. I imported my local DB to RDS
Now In my Ec2 I onlu have PHP not mysql as my db is in RDS
In my ec2 php is running In check it with simple hello world echo file.
But mysqli_connect script is giving connection time out error. I used the same credentials as I used to connect to workbench. And I am also using the right script of mysqli_connect.
My doubt is Is it because of I did not installed mysql in my ec2 linux server. But Why I need mysql in ec2 if I have successfully setup DB in RDS.
First thing is that to install mysql-client and try that again. There can be several issues if it doesn't work even after trying to connect with mysql-client and consider those as well.
The state of the RDS instance should be 'available'. Otherwise it won't connect to any.
Check whether your EC2 instance IAM role has the permission which needs to access RDS instance. If your IAM role doesn't have permission then it won't get permission to connect and it will timeout after a while.
*It's better if you can post some code here.

Cannot connect to amazon web services database

I have made a website and it is currently hosted on Netfirms.
The following is my code that I'm using to connect to my amazon web services database:
<?php
$connect_error = 'Sorry, we\'re expericing connection problems.';
mysql_connect('xxxxxx.xxxxxxxxxx.us-west-2.rds.amazonaws.com','myusername','mypassword') or die($connect_error);
mysql_select_db('invest') or die($connect_error);
?>
However, I'm getting this error:
Warning: mysql_connect(): Can't connect to MySQL server on
'xxxxxx.xxxxxxxx.us-west-2.rds.amazonaws.com' (111) in
/hermes/bosnaweb03b/b2442/nf.liangbros/triumph/core/database/connect.php
on line 6
What can I do to resolve this? Is it something wrong with AWS or is there something I can set on netfirms and/or AWS? I made the dev website and tested it using easyPHP on my localhost and everything works (successfully connects to amazon web services) but after uploading all my files onto my netfirms host, it cannot connect to AWS database. I need this site up and running before end of month December, please help! Thanks!
I have tried to change the security group on my AWS database to the following:
netfirms (sg-ce2d23aa)
For this security group, I set the following:
inbound settings
The following is a snapshot of my database on AWS:
AWS database
Your RDS has a security group, and it's also part of a VPC that has it's own security group. Right now your RDS allows all traffic that can reach it, but I would be willing to bet that your VPC security group does not allow the traffic coming or going to pass to the subnet. I would also recommend using the MySQL/Aurora (3306) vs the All Traffic option, then set the source to 0.0.0.0/0. You also need to check your EC2 instance security group to insure it has the right inbound and outbound settings that you need.

AWS RDS: How to access/connect to RDS MySql DB From localhost

I am very new to Amazon Web Services, I have created Mysql DB on RDS and stored some data.
Now i want to connect to RDS db from localhost(which is in running on my desktop) ,Tried as fallow in my PHP connection.
$con = mysql_connect("XXXX.XXXXX.XX-XX-X.rds.amazonaws.com:3306", "XXX", "XXX");
But getting error as fallows
Could not connect: Can't connect to MySQL server on 'awsniti.XXXX.rds.amazonaws.com'
Also tried giving my local IP address to Inbounds of Security Group. But couldn't connect.
googled a lot, but not able to find right answer.
Please help me with this issue.
Adding the internet IP of your local network/machine on the security group associated with your RDS database should work. But I prefer to create a SSH tunnel through a server that I already gave access to the database. This way you don't have to care about the security group configuration every time you need to connect from a different IP address.
If you are on Linux or OSX you can run locally
ssh -f user#your-web-server.com -L 3306:XXXX.XXXXX.XX-XX-X.rds.amazonaws.com:3306 -N and then connect localhost:3306 from PHP to access the RDS database. If you are on Windows it's also possible to create a tunnel using Putty (http://bit.ly/1GQmaYo)

Laravel 4 Connect to EC2 MySQL from remote domain

Not sure if what I am attempting to do is possible or not. I just launched my very first EC2 instance running Ubuntu 12.04 and successfully installed Laravel 4. I have the database working just fine on the EC2 instance and I am able to connect to it with MySQL Workbench on my local machine using a .pem SSH key.
I will be using EC2 to handle certain aspects of a product that I am developing to ensure improved reliability - client side users will be interacting with this primarily through CURL. I want to be able to have my non-EC2 website, also running Laravel 4, use the MySQL database that I set up on my EC2 instance.
I tried changing my app/config/database.php file to include the EC2 instance IP address and MySQL credentials, when Laravel attempts to connect it returns a timeout error.
I modified my.cfn and commented out bind-address = 127.0.0.1, I do not seem to have the skip-network that I have seen mentioned. Still no joy.
Any suggestions?
In side MySQL (PhpMyAdmin if you installed it) -> Users overview -> Edit your user with Host is
%
That is mean, you can connect to MySQL in anywhere with command
mysql_connect($IpOfYourHost, $UserAbove, $Password)
Maybe this helps you. :)
Resolved
I changed bind-address to 0.0.0.0, created a new MySQL user - 'user'#'%', and had my host whitelist the IP. Done!

Categories