PDO Connection Timed out Between EC2 and Aurora - php

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.

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.

Lavavel migrate not work in a LAMP AWS instance with MySQL RDS DB --> SQLSTATE[HY000] [2002] Connection timed out

I have setup an EC2 aws instance with Apache, PHP 7.2, Git, Composer and a RDS MySQL 5.7 database.
I followed the AWS official tutorials and others like Deploying and Scaling a Laravel Web App on AWS — Part 1 but I can't finish the laravel project installation. Using ssh terminal connection, in time to migrate (sudo php artisan migrate), I get the response:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from information_schema.tables where table_schema = database_name and table_name = migrations)
When I try this same connection using MySQL WorkBench, I can connect, create or drop a table for example.
I think the .env file or config/database.php are properly set, but I can't explain why I get this error. Any help please? Thanks
Seeing as this is a connection issue:
Between your EC2 instance and the RDS MySQL database: you may have to add a rule to your security group allowing the standard MySQL port. If you've made changes to the Network Access Control List attached to the subnet that your EC2 instance is in, you'll also want to modify the NACL to allow inbound AND outbound traffic from the instance to the RDS database.
Between your RDS instance and Workbench: Check the security group on the Database (not the EC2 instance's security group)

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.

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.

Connecting to Amazon Aurora with Laravel in production

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.

Categories