Laravel

Connect Laravel to remote MySql DB with SSH

Quick way of connecting remote database with SSH key, will be by running SSH tunnel.

ssh -i ~/.ssh/key.pem -f username@000.000.000.00 -L 33061:remote-database-host:3306 -N

Once you have tunnel running, in app .env file you can connect database by simply following the config below.

DB_HOST=127.0.0.1
DB_PORT=33061
DB_DATABASE=db_name
DB_USERNAME=db_user_name
DB_PASSWORD=db_password

That’s it, cheers ๐Ÿ™‚

Author: Danyal
I'm a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.