

The thing to pay attention to is the port, this should match the local port we set up in our SSH command. 'password' => env( 'REMOTE_DB_PASSWORD', ''), 'username' => env( 'REMOTE_DB_USERNAME', 'forge'), 'database' => env( 'REMOTE_DB_DATABASE', 'forge'), In config/database.php you can set up any database connections.Īdd a new section to the connections array key like this: 'remote_mysql' => [ Now that we have our SSH connection set up, let's see whether we can connect to that database. As soon as you stop this command, the SSH tunnel will be closed and you can no longer reach the external database. Now, to actually start the SSH tunnel, execute this command and leave that console open. So, my remote MySQL database is running on 111.222.333.444, but on that machine it is accessible on 127.0.0.1:3306 (aka localhost). So, we're describing that whenever we connect locally to port 13306, we want to forward these commands to 127.0.0.1:3306 on our remote host, which is 111.222.333.444. 13306 is the local port we want to forward.-L is the start of our port forwarding configuration.

-N describes we don't want to execute any remote commands, we just want the port forwarding.
#Psql ssh tunnel how to
The first part, -i /path/to/id_rsa, is describing how to authenticate to the remote server. The last part (we'll get back to the first parts), is describing that want to connect to a server at 111.222.333.444 with the username root. Let us break down what that command is doing. If you understand what is going on, just skip to the database configuration. N -L 13306:127.0.0.1:3306 SSH command was new to me, so I want to describe it in full detail. To start a new SSH tunnel, run the following command: ssh -i. Here is an explanation of how to accomplish that. I can only connect to that database over an SSH connection using an SSH key. I've been writing an artisan command to import data from a remote MySQL database.
