Page 1 of 1
MySQL through SSH Tunnel?
#1
Posted 09 April 2012 - 04:17 PM
I need to connect into a remote MySQL DB that allows only localhost connections.
Is there an elegant, Yii way to create a MySQL connection through an SSH tunnel via the main config file?
Is there an elegant, Yii way to create a MySQL connection through an SSH tunnel via the main config file?
#2
Posted 10 April 2012 - 01:23 AM
Before initializing db component, you need to start tunel as(on Linux servers):
ssh -f user@mysql-server.com -L 3306:mysql-server.com:3306 -N
Once tunel is opened, in main.php config file, for db host use localhost, and enter your mysql server username/password.
ssh -f user@mysql-server.com -L 3306:mysql-server.com:3306 -N
Once tunel is opened, in main.php config file, for db host use localhost, and enter your mysql server username/password.
Zurmo: Yii Powered Open Source CRM
zurmo.org
zurmo.org
#4
Posted 14 December 2012 - 04:37 AM
Can someone clarify where you have to start this ssh tunnel?
For me it seems that this is not possible in the main.php config file? So where is the db component initialized?
For me it seems that this is not possible in the main.php config file? So where is the db component initialized?
#5
Posted 14 December 2012 - 04:47 AM
Hm, I wonder if MySQL's built-in SSL transport weren't the better solution. One could still restrict IP access via iptables.
@Pakotski: Chances are that you cannot do that via PHP. Write a script for initd/systemd/upstart to take care of that.
@Pakotski: Chances are that you cannot do that via PHP. Write a script for initd/systemd/upstart to take care of that.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
#6
Posted 14 December 2012 - 05:51 AM
Pakotski, on 14 December 2012 - 04:37 AM, said:
Can someone clarify where you have to start this ssh tunnel?
For me it seems that this is not possible in the main.php config file? So where is the db component initialized?
For me it seems that this is not possible in the main.php config file? So where is the db component initialized?
In continuation to what already answered, while it is possible (with SSH keys and passwordless login...) you would not wish to setup and destroy SSH tunnel with each request since it takes relatively lots of time to establish this tunnel. A few seconds usually.
Its like you're actually digging up a tunnel from the web server to the MySQL server and you wouldn't want to destroy and build it again on each request.
Therapeutic PHP sessions My LinkedIn Profile
#7
Posted 14 December 2012 - 05:55 AM
Actually, I just remembered that I once used a setup of xinetd+stunnel in order to protect a cvs server of mine. It's not the fastest solution, but at least for cvs response times were acceptable.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
#8
Posted 14 December 2012 - 07:25 AM
OK, so the best solution seems to setup a SSH tunnel on startup of the server. Will try!
#9
Posted 14 December 2012 - 08:01 AM
Pakotski, on 14 December 2012 - 07:25 AM, said:
OK, so the best solution seems to setup a SSH tunnel on startup of the server. Will try!
If this tunnel is critical or important enough, be sure to check the availability of the tunnel. It can hung up sometimes.
Therapeutic PHP sessions My LinkedIn Profile
Share this topic:
Page 1 of 1

Help















