Staging and previewing a site
Posted by Wolf Leonhardt on 22 April 2015 06:18 PM
Very often clients want to build a site while leaving the original site intact while the new site is being put together.
This then leads to the problem of how to preview a site using the normal URL (ie www.chinookwebs.com). You can put in a alias for example stage.chinookwebs.com but in some cases (think wordpress) this causes an issue when you try to go live with the site.
Fortunately there is a trick that you can do so that even though you are building a staging site, you can see it as if it is a live site.
Before I explain the trick, we need to understand how going to website works.
When you type in the website name (for example www.chinookwebs.com) the web browser will use the "dns" (domain name servers) to resolve (figure out) the IP address of the web site you wan to go to. ( in our example www.chinookwebs.com resolves to 188.8.131.52) BUT what if I wanted to build a new site and it is on a different IP (for example 184.108.40.206).
So here is the trick, almost all modern operating systems check a local (on your machine) file before querying (asking) the "dns" servers. That file is called a hosts file and anything we put in there will be used instead of the "dns" query. If I wanted just my machine to go to the new staging site, I would enter the IP and the web address in that file.
# Copyright (c) 1993-2009 Microsoft Corp.
# localhost name resolution is handled within DNS itself.
So how do we edit the hosts file? We are going to use notepad for that. First thing we need to do is make sure we open notepad as an administrator. This can be done by finding it in our menu (depending on what version of windows you have) and "right clicking it". This should allow you to select the option to "run as administrator". So once notepad is open in the correct manner we navigate to windows\system32\drivers\etc . Now when you do that you might not see the hosts file and that is because notepad automatically tries to show only txt files. All you need to do here is use the drop down (lower right hand corner) and change the selection from "text documents" to "all files".
Once you have made changes to the hosts file, there is one more thing to be aware of. On many systems the file extensions (ie .txt) are not visible, so you need to make sure the hosts file you save is not accidentally saved as hosts.txt (your changes won't work). The trick there is to again when saving , select "all files" and not the default txt file.
On a MAC system you would launch Terminal then type in sudo nano /private/etc/hosts. The remainder of the process is similar to the windows method.