Connect to Amazon RDS using PHP

I am trying to connect my RDS instance with my PHP connection file.

This is what I have in the file:

define('DB_SERVER', 'localhost'); define('DB_USERNAME', 'User Name'); define('DB_PASSWORD', 'Password'); define('DB_DATABASE', 'DATABASE'); $connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error()); $database = mysql_select_db(DB_DATABASE) or die(mysql_error()); 

I replaced localhost with my rds thing url, username and password with my RDS Instance user and passed the database name to the one I installed when I created this instance. But it doesn't seem to work.

Is there anything else I should do that I don’t know about or should work?

+4
source share
7 answers

Some ideas:

  • Try using the actual IP address of the instance, then it should work.
  • Did you allow access to your database instance?
  • You can watch Start with Amazon RDS to properly configure your RDS instance.
+8
source

RDS instances do not have a static IP address bound to them; you always use the endpoint for the host. For instance:

database1.jlsdfjhgsdf.us-east-1.rds.amazonaws.com

If you connect to an instance with a username other than the root database account, you must provide user privileges.

Check security group settings. If you are connecting to another instance of EC2 on Amazon, you will need to attach this security group. If you are trying to connect from outside AWS, you will need a "white" IP address that you are accessing.

+12
source

I ran into a similar problem trying to connect an Apache EC2 server using PHP for a MySQL RDS instance. From above, I could establish a connection through the CLI - once in mysql operation mode it will be indicated with which user you are logged in, plus the port, server name, etc. It turned out that some AMI images have SELinux forced - this means that the Apache server cannot send network requests, as these gentlemen pointed out ( http://www.filonov.com/2009/08/07/sqlstatehy000-2003-cant- connect-to-mysql-server-on-xxx-xxx-xxx-xxx-13 / )

Other items:

  • Make sure the inbound ports are set for your RDS DB
  • In MySQL, make sure the host is set to "%" and not localhost
  • Always use the endpoint string to connect to the RDS IP address change
+4
source

I recently had a lot of problems with this, but I was able to fix it. I made sure that my security groups (for RDS and EC2) allow each other. I managed to run my script from the terminal and connect to my database also from the terminal, but I could not get the script to start / connect to MySQL from the browser. It turns out I did not have mysql-server installed - as soon as I installed it and restarted httpd and mysqld, it worked like a charm.

This article led me to install a mysql server and the service starts / restarts. Hope it helps! - http://www.rndmr.com/amazon-aws-ec2-easy-web-serverset-up-guide-with-a-mac-and-coda-2-256/

+1
source

Click here on the Menu (orange).

Just accepts all incoming connections.

+1
source

I tried to connect to my DB instance using node -mysql. I found that the endpoint provided by RDS did a DNS lookup. Followed this and changed the url to this. I was only able to connect to mysql through the command line until then. When I changed it to the endpoint after the search, node-mysql was finally able to connect.

0
source

I also had a connection problem between EC2 (Apache + PHP server) and RDS (database server) when after the tutorial on http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateDBInstance.html .

I solved this by using a double quote when specifying the connection value, while the manual uses a single quote.

 define('DB_SERVER', "localhost"); define('DB_USERNAME', "User Name"); define('DB_PASSWORD', "Password"); define('DB_DATABASE', "DATABASE"); 
0
source

Source: https://habr.com/ru/post/1399990/


All Articles