Connection refused when trying to connect to AWS RDS - php

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.

Related

Amazon RDS timeout with php pdf

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.

PDO Connection Timed out Between EC2 and Aurora

I have a multi server set up at Amazon, an Aurora DB cluster, a staging EC2 instance (1), a development EC2 instance (3), and I just launched a production EC2 instance (2).
All of the EC2 instances were created in Laravel Forge and are deployed via Envoyer.
All 3 EC2 instances use the same host and login credentials for the DB cluster, just different databases.
Server 1 and server 3 connect to the DB just fine, but the new production server 2 throws the following error:
[PDOException]
SQLSTATE[HY000] [2002] Connection timed out
Server 1 and server 2 are exactly the same Laravel application, just different branches, and have different .env files, but the DB credentials are exactly the same.
Does anyone have any ideas as to why I would get a timed out error when the credentials are the same?
I've double checked the security settings for Aurora and it's set to receive all public traffic (for the time being) so it's not that.
How can I trace this in Laravel or another tool to troubleshoot this?
Also I can connect remotely to the DB from my Macs through SequelPro with no issues as well.
Both branches of the code are up to date as well. It's simply the production server that won't connect.

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)

How can I connect to MySQL database on a dedicated Windows 2003 server from EC2 based app server with PHP

I have developed a web application that uses PHP and MySQL and has all been running fine from a single development server. I now want to separate things a bit and place an app server within Amazons cloud that will receive and process uploaded files. The database is going to remain on the dedicated server but will need to be accessed by the EC2 instance.
Heres what I have tried so far...
In phpMyAdmin I added a new user to the privileges table. I gave it the elastic IP address from AWS as the host name, a new password and granted privileges to INSERT, SELECT and UPDATE.
In the PHP scripts on my EC2 based app server I included this username, password and the domain name of the location of the mysql server (example.domain.net) when connecting with mysql_connect
I have a simple test page that tries to SELECT and echo some results from the database but get the following error -
Could not connect to MySQL: Can't connect to MySQL server on 'example.domain.net' (4)
What could this mean, what have I missed, are there any other issues such as trying to do this from within EC2 that will cause other problems?
cheers all
Turns out the only other thing I needed to do was to open port 3306 on the database server to allow access. Did this by going to Control Panel -> Windows Firewall -> Exceptions -> Add Port ["SQL", 3306]
Now it works great!

Categories