Testing a website from server before DNS switch via SSH Tunneling

This is a continuation to the blob I previously posted. Since then I have found another way of testing a site without switching the DNS.

What this approach does is, it assigns the port from the server (that you are migrating your site to) to a port on your local machine. And you can add your domain name on the hosts file with the IP and you should see the site loading on your browser only. More details below:

Requirement: You need to have ssh access to your server obviously and have a tool on your local development PC that lets you ssh via command line.

  • Open the terminal and type the command below on your local PC.
ssh -L localPort:remoteServerName:remotePort [email protected]

localPort : is the port where you want the application to be mimicing on your local pc.

remoteServerName: Hostname of the remote server where your application is being setup and migrated.

remotePort: The port number on the Remote Host server where you application is being servers by Apache or other web server.

username: The user name that you will use to ssh to the remote server.
  • After doing the above, update your hosts file on the local development pc to point the domain name you are trying to test to . example : www.testsite.com
  • If you chose port 80 or 443 for localPort, then type the domain https://www.testsite.com on your browser and it should show the site that is running on the remoteServerName:remotePort.

You should now be able to test all your sites running on your servers using the above method via browser unlike the curl method mentioned in my previous port.