简体   繁体   中英

Connect a remote mysql server to symfony(doctrine) over ssh

im creating a symfony Application and I need access to a database that is on another server(via ssh). How would I do something like that?

I could'nt find any option for that in the doctrine documentation.

if the database server not open the database port, so you must be use the ssh as the middle protocol like this.

$host = 'remote host';
$sshuser = 'ssh user';
$sshpass = 'ssh password';
$dbuser = 'db user';
$dbpass = 'db pass';
$dbname = 'db name';

shell_exec("ssh -p$sshpass ssh -o StrictHostKeyChecking=no -f -L 3307:127.0.0.1:3306 $sshuser@$host");

$dbh = new PDO('mysql:host=127.0.0.1;port=3306;dbname=' .$dbname. '', $dbuser, $dbpass);

then use $dhb to interact with your database.

may be you must write some code on doctrine library for do your idea.

You have to open an SSH tunnel.

See Can I SSH to MySQL with the GUI tools? or Access Your MySQL Server Remotely Over SSH .

For parameters.yml this looks like a local MySql server, wich menans there's nothing special.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM