Search code examples
laravelserverlesslaravel-valetlaravel-6

How to connect to Laravel Vapor database for local development?


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.


Solution

  • 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.