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.
Related
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.
I've developed a Laravel app locally and connected locally to a database instance of Amazon Aurora. Had no problems connected to that DB locally but now that I've migrated to production, I get a
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '[AMAZON AURORA URL HERE]' (4)
error. I'm hosting on MediaTemple. I've got the database access on Amazon set to public, so not sure why I wouldn't be able to connect using the same settings I'm connecting to locally.
Make sure to check your inbound security group settings.
When you create a new RDS instance, the launch wizard automatically creates a security group that allows your local IP (so it makes sense you've been able to log-in on your local dev).
Make sure to go in to that security group and also add the CIDR/IP of your MediaTemple server.
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)
I have authorized connection to RDS by adding the CIDRs as mentioned in the AWS documentation.
So I am able to connect and manage my RDS instance from local system(I added my local ip in CIDR)
My application instance is resting on a server that is outside AWS and is unable to connect to the database even after adding my application server IP to CIDR allowing only one IP /32.
when i try to open my application, i get this error
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '<rds endpoint>' (4)
Did others face the same problem?
How did you go about solving it?
Regards
Ravi
Is your application behind a firewall or front-facing? Does it have a public IP or is it using an internal IP on your network? It may be an issue that you may need to allow the front-facing IP access on your security group to access the RDS instance if your application server is behind the firewall.
The issue is fixed now.
Realized that my mysql port 3306 was blocked on the server and was not allowing any communication responses.
Thanks for the help though.
edit:
So, here's how the issue was solved.
RDS allows incoming connections from two sources.
1. Trusted IP
2. ec2- security group
When allowing connections from any outside IP, we have to add that IP or IP range to the security group in RDS instance. It is available in RDS console.
Click here to know more details
The outside server also should allow communications via mysql port(3306), so make sure that you enable 3306 on your application server.
Change your host to the RDS endpoint and test. It should work.
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!