Quick way of connecting remote database with SSH key, will be by running SSH tunnel.
ssh -i ~/.ssh/key.pem -f firstname.lastname@example.org -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 🙂