Advanced Website Testing via the HOSTS File

Often a web hosting client will signup with a new Hosting account with the intent of transfering an existing website from another cPanel server over to AU Business Hosting, or designing a new website on the new AU Business Hosting account and then pointing the domain to the new server when the new design is finished. This tutorial explains an advanced method for testing your website on a new server, long before you update the domain name to point to the new server.

Mod_UserDir

Typically, website owners are able to upload their website files to the server and test the website from the server using a special link which is provided in the Welcome email message they received after they signed up for their hosting account.

Here is an example of such a link: http://72.29.64.58/~username/

This special link is provided by a module that is installed on the web server known as 'mod_userdir'. This module makes the specific website on that server available by matching the username in the '/~username/' part of the URL with the actual VirtualHost entry in the servers configuration file (httpd.conf)

This special link works out pretty well for those with some static HTML websites, but it causes errors with websites which rely on the domain name being used in the URL (typically PHP or Perl based websites), and HTML sites which use image links which refer to the site root instead of using linking in relation to the location of the file itself (relational link).

Because of this, we do not recommend using this link to test your website to make sure its fully functional.

The HOSTS File

The advanced method of testing your website is to trick your computer into thinking that your domain is already resolving to the new web server. This can be done with a simple edit of the HOSTS file on your computer.

Long before DNS servers were part of the Internet, all machines kept an updated HOSTS file which contained the name (like a domain name) and the actual network address of the machine. After the Arpanet/Internet got too large for this file to be downloaded from a central location by every computer, the DNS system was invented to replace the HOSTS file. Even though this HOSTS file is no longer in use, it still exists on modern operating systems and actually overrides the DNS records your computer receives or has cached.

On Windows XP systems this file is located at C:\WINDOWS\system32\drivers\etc\hosts

For Linux systems its usually located at /etc/hosts

Windows XP Users - If you cannot find this file, you may want to simply use the file search tool built into Windows XP at Start > Search > For Files or Folders.







Once you find the file, right-click on the file and choose to open the file in Notepad or another non-formatted text editor (Wordpad or MS Word not recommended).

Typically, if you try to open the file, Windows should prompt you which program you wish to use to open the file (since it has no file extension).




After you've opened the file, you should see something similar to the following:




Enter a line which begins with the IP address of your new server, and ends with the domain name for your website, right below the "127.0.0.1 localhost" line. After you've done this, enter a line below it which is indentical, but include the 'www.' at the beginning of your domain name. We've done it using 'johndoe.com', with 72.29.64.58 as the IP address of the server.




After you've done this, save the file (File > Save), and then close the Notepad program.

If you open a new browser window and try to visit the website, you'll see that it pulls up the version that is on the new server, just as if the domain was actually resolving to the new server. This is obviously the best way to test your website because it actually emulates the behavior and performance of the website had the domain actually resolved to the new server.

After you are done testing the website, open the 'hosts' file up again in Notepad and remember to remove the lines you've added. If you do not remove these lines later, and forget about them, it may lead to confusion or problems which will confuse you and the technicians you speak to regarding issues which may arise.

  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

What is an SSL Certificate?

An SSL Certificate secures your website, and is vital when your business requires you to accept...

How will I be billed?

  Please note that all of our packages are set up for automatic renewal. Until we receive...

What can I do if I didnt receieve my welcome email?

When new accounts are created, clients will receive a welcome e-mail that explains the details...

How long does it take for an account to be setup?

From the time that you sign up for a shared plan, you can expect the Welcome E-mail within 24...

What is the most secure method for accessing my cpanel/whm account?

Each server provides both SSL and normal methods for accessing your hosting account's interface....