Ok folks here we go,
Webserver2 (New VPS Server) needs to access our Production Database.
Webserver1 (Old Hardware Server) has direct access to the Database through port 3306 on the LAN.
Database1 (On a third Separate Hardware Server No public IPs) on same LAN as Webserver1
I can successfully create an SSH connection to webserver1 from webserver2 now using that connection I need to connect to the MySQL database hosted on Database1. Everything functions from the shell, I just need help getting the mysql connection to use the ssh tunnel.
from shell it works like so…
Login via ssh to webserver1
use mysql -h database1 -u username -p to access database.
Here is the code so far…
[php]<?php
$connection = ssh2_connect(‘yoursite.com’, 2222, array(‘hostkey’=>‘ssh-rsa’));
if (ssh2_auth_pubkey_file($connection, ‘username’,
‘id_rsa.pub’,
‘id_rsa’, ‘’)) {
echo “Public Key Authentication Successful\n”;
} else {
die(‘Public Key Authentication Failed’);
}
$tunnel = ssh2_tunnel($connection, ‘database1’, 22);
//I understand this is another ssh connection and as such fails but I cannot find a good example of using mysql_connect with the SSH2 connection.
?>[/php]