I am using Laravel 5.0. I Want to Know How to Access Remote Database using SSH.
database.php
'mysql' => [
'driver' => 'mysql',
'host' => 'www.xxxxx.in',
'port' => '2222',
'database' => 'xxxx_xxx',
'username' => 'xxxxx_xx',
'password' => 'xxxx0xx',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
Use the following steps to connect remote database using ssh tunnel in laravel applications; as follows: Open ssh tunnel using the following ssh command; as follows: The ssh tunnel will open, but if you want to keep alive open that ssh tunnel then you can follow the below given steps.
Bellow are the steps you can use to connect your DBeaver client to a remote database server via SSH. Note that you only need to do these steps once. The connection configurations will be saved and you can re-use them by right-click + connect. This guide is created using DBeaver version 6.3. 1. Create a new connection
Laravel includes a helpful command for tailing the laravel.log files on any of your remote connections. Simply use the tail Artisan command and specify the name of the remote connection you would like to tail: Laravel Envoy provides a clean, minimal syntax for defining common tasks you run on your remote servers.
The SSH facade provides the access point to connecting to your remote servers and running commands. The configuration file is located at app/config/remote.php, and contains all of the options you need to configure your remote connections. The connections array contains a list of your servers keyed by name.
You should create SSH tunnel.
More about SSH tunnel and some examples here: http://chxo.com/be2/20040511_5667.html
Example:
ssh -fNg -L 3307:127.0.0.1:3306 [email protected]
mysql -h 127.0.0.1 -P 3307 -u dbuser -p db
Of course, then you need to change credentials:
'mysql' => [
'driver' => 'mysql',
'host' => 'www.xxxxx.in',
'port' => '3307',
'database' => 'xxxx_xxx',
...
],
You will need to create an SSH Tunnel as Alexey says.
You will also need to port-forward the MySQL connection port to your local; as Alexey has done also.
Then in your Laravel config, set the port to the forwarded port. So building off Alexey's answer, your database configuration would read thus
'mysql' => [
'driver' => 'mysql',
'host' => 'www.xxxxx.in',
'port' => '3307',
'database' => 'xxxx_xxx',
'username' => 'xxxxx_xx',
'password' => 'xxxx0xx',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
EDIT
In case Alexey's answer goes away, these are the relevant parts to my answer
Create the ssh tunnel
ssh -fNg -L 3307:127.0.0.1:3306 [email protected]
Connect locally using
mysql -h 127.0.0.1 -P 3307 -u dbuser -p db
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With