Knowledgebase: Getting Started
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 74.3.176.78)  BUT what if I wanted to build a new site and it is on a different IP (for example 74.3.176.77).

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.
Here is an example of what that might look like:

 # Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1       localhost# ::1             localhost
74.3.176.77   www.chinookwebs.com      #so this entry points www.chinookwebs.com to the ip ending in 77 instead of the "live" 78 address
74.3.176.77   chinookwebs.com

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.

(0 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).