Ad

Laravel Forge - Can't Connect To External DB Server (Connection Timed Out)

- 1 answer

Going to be quick and straight-forward, as I'm sure I'm just overlooking something simple.

I have 3 app servers load balanced and therefore a separate database server. I set up my env properly to point to the DB server's IP instead of 127.0.01, and input the correct password and username for a user I created. However, when I try to deploy the servers, it fails with a 2002 error that the connection timed out. I've tried looking through all other threads with similar issues but none seem to really be having the same issue.

Example of env (except for username and password, obviously)

DB_CONNECTION=mysql
DB_HOST=3.19.111.11 -- External Database IP
DB_PORT=3306
DB_DATABASE=xxx -- Correct database name (as seen in Forge dashboard on DB server)
DB_USERNAME=xxx -- Correct username (just set up this user)
DB_PASSWORD="xyz123" -- Correct password for aforesaid user

I can connect to the database server via TablePlus, so the issue is localized to something I'm doing on the app servers themselves, but I can't see anything wrong.

As additional information, I have setup the individual servers network's to allow them to connect to the database server and vice versa, although I'm not sure that was necessary.

Adding an envvar for APP_URL and setting that to the DB's IP and changing DB_HOST to 127.0.0.1 changes the error to be a Connection Refused error, whether or not that's better.

Ad

Answer

Turns out the issue was that despite opening up the network on Forge's control panel, they weren't actually allowed to each other. Going into EC2 dashboard and making a security group that opened up port 3306 to each app server's private IP solved the issue.

Ad
source: stackoverflow.com
Ad