1

I have two remote dedicated servers, one webserver that runs Apache, and one db server that runs MySQL.

The Apache server is visible on the Internet of course, but the second server is visible only to the Apache server because they are connected with LAN.

I need to connect to the remote MySQL server through Internet from my home-pc, but only Apache server is visible to my home-pc. How can I set up port-forwarding from my Apache server to the MySQL server so I will be able to "see" the MySQL server from my home-pc?

This question is a follow-up from my first question: https://stackoverflow.com/questions/4159256/connect-to-remote-mysql-server-from-my-application-problem-is-that-mysql-server in which you answered me and helped me a lot by telling me to do "port-forwarding".

I looked over the Internet, and I can't find a good how-to to do port-forwarding. I'm an experienced programmer, but have little experience on hardware and networks. I can understand though what must be done, so I just need a little help to sort things out. :)

P.S. The machine that Apache is running is on CentOS; the MySQL server also runs CentOS. P.S.2 webserver runs WebHostManager. I don't know if that makes any difference or it can be made easily through this, I just mention it.

2
  • 1
    This should be asked on serverfault
    – rwilliams
    Dec 2, 2010 at 10:27
  • How do you intend to connect to your mysql server? Web? Navicat? Command line? Dec 2, 2010 at 10:29

1 Answer 1

1

Fire up your SSH client on your desktop.

Type this in (stuff below explains what you are replacing):

ssh -L desktop_port:database_host:database_port apache_username@apache_host

  • desktop_port: 3306 (only use this if you aren't running mysql locally)
  • database_host: your database host (use domain name or ip address)
  • database_port: 3306 (change if you aren't using the default port)
  • apache_username: the username used to login to your apache server
  • apache_host: the apache host (the domain name or ip address)

When prompted, enter your apache_username's password. Keep this terminal open as the tunnel will close when you close this connection.

An example that works for me:

ssh -L 3306:db:3306 user@web

When you are all done, just type exit on your terminal and the connection will be gone.

You must log in to answer this question.