2

I'm using Laravel Vapor for serverless deployment and Laravel Valet for local development. I've chosen a private serverless database on Vapor and created a "jumpbox" in Vapor to connect with that database via SSH in other applications. But how do I connect to the database in my Laravel app for local development? When I view my app using Valet, on e.g. "website.test", I get a connection error because my database connections aren't set up in the .env file. The jumpbox provides a username and password, but also a SSH key, and I don't know how to include that in my .env file so I can connect locally.

Holly
  • 3,601
  • 1
  • 17
  • 23

1 Answers1

1

You can create a local pipe using ssh to the server and map the remote database port to one of your local ports, that way MySQL will appear like it's working locally and you can just use localhost and the port you chose in the .env.

You'll need to search how to do the mapping in your specific system but it's called SSH port forwarding and it's not that hard to achieve.

Eduardo
  • 220
  • 2
  • 9
  • Thanks for this. I did a search and found the process to be a bit confusing, so I'll leave this question open a little longer in case anyone else has any input or detailed instructions. – Holly Oct 04 '19 at 16:47
  • 2
    I can't give you a command that will work with 100% certainty but basically it goes something like this. `ssh -L :localhost: user@example.com` so if you want to make that database behave as if it were local: `ssh -L 3306:localhost:3306 user@example.com` should do the trick in case of a normal RDS instance but thinking about the issue a bit further, you might want to access the jumpbox as a vpn instead, it might be easier than juggling port forwards and the jumpbox won't have that :3306 port running anything. – Eduardo Oct 05 '19 at 00:53
  • Have you managed to connect to your remote Vapor controlled DB in the end from local? @Holly – Dr. House Aug 24 '20 at 13:33
  • Thanks for asking Mkey & sorry for the delay. Yes, I did... but only because I ditched the private DB in favor of a standard public one. Never did figure out the jumpbox part. – Holly Jan 21 '21 at 01:33