1

How can I connect to a remote database via SSH tunneling in Symfony2?

I've found the PHP snippet, but how can I integrate it in Symfony

<?php
   $smysql = mysql_connect( "127.0.0.1:3307", "dbuser", "PASS" );
   mysql_select_db( "db", $smysql ); 
?>

Hope it makes sense.

user1236048
  • 5,542
  • 7
  • 50
  • 87

2 Answers2

2

In your parameters.yml file change the database_port

parameters:
    database_driver:   pdo_mysql
    database_host:     127.0.0.1
    database_port:     3307
    database_name:     ...
    database_user:     ...
    database_password: ...

This will work when the ssh tunnel exists. Otherwise you'll get a connection error.

james_t
  • 2,723
  • 1
  • 15
  • 20
1

You do need to setup an SSH tunnel on your local port 3307 first.

If you're on windows you can follow this tutorial

Rutger van Baren
  • 7,964
  • 2
  • 24
  • 24