How To… Test cPanel Websites Using HOSTS File

How To...Published January 6, 2012 at 1:50 pm No Comments

Whenever someone transfers a cPanel site from a remote server to their existing hosting account, they must first transfer all of that accounts cPanel data (cpanel files, web files, e-mails, stats, mailing lists, mysql dbs, ect) to the new server. Once the data is located on the new server, one can simply update the DNS records of the domain name in question to point to the new hosting account. But how can one know if all the data was transferred to the new server correctly? Many times, the new server or hosting account will have slightly different configuration files (be Apache, MySQL, PHP, ect) that will affect how the site functions. There are 2 different ways one can test the functionality of their cPanel based website before switching over their DNS settings to the new server.

Method 1: Mod_UserDir

This is a fairly basic way of testing website functionality prior to changing DNS settings. After transferring the cPanel data of the website to the new server, one can access the site on the new server by using a URL that consists of the server’s main IP address and the corresponding username of that account. The link looks similar to the following:

http://66.7.213.18/~username

This link is provided by a module that is installed on the webserver known as ‘mod_userdir’. The module makes that account on the server accessible by matching the username of the account in question with the VirtualHost entry in the servers configuration file (httpd.conf).

While this method can be helpful for individuals who operate basic HTML sites, it can cause problems for sites that require the domain name being used in the URL (such as PHP or Perl based sites, for example). HTML sites that use images links that refer to the site root (instead of using a relational link) may also see errors using this method.

Method 2: HOSTS File

The full proof way of testing your site before it comes live on your new server is by manipulating your local computers HOSTS file. Please note that one should exercise caution when modifying this file as incorrect or erroneous entries can cause many problems down the road.

What is the HOSTS file? Long before DNS servers directed traffic on the internet, each individual computer was required to keep an updated copy of a global HOSTS file with all domains and their respective IP addresses on it. After the internet became too large for this method, the DNS system was put in to effect to replace the HOSTS file. Even though this file is now largely defunct, it is still present in most modern operating systems and can be used troubleshoot issues such as this. The location of the HOSTS file varies by operating system, but here is a short list to help you find yours: http://en.wikipedia.org/wiki/Hosts_(file)

Once you find the file, open it with a non-formatted text editor such as Notepad (not Microsoft Word or Wordpad). After opening the file with Notepad, you should see something similar to the following:

Under the ‘localhost’ entry, enter a new line starting with the IP address of your new server, then press tab, and then the domain name of your site. Under this new entry, enter an identical entry, only this time with a www. proceeding your domain name (www.domain.com). In the following example, we used 72.29.64.58 as the IP address for our domain johndoe.com:

After this has been done correctly, save the text file and close notepad. Now once you visit the domain name in any browser, it will resolve to the instance of the site on the new server. This mimics what will happen once the domains DNS entries are changed for the domain name to point to this new server. Please note that this change will only effect the local computer which you modified the hosts entry on, all other computers will resolve the domain name according to it respective nameservers.

After you are done troubleshooting, it is important to remember to remove these entries from the HOSTS file as they may lead to issues later on.

Leave a Reply

(required)

(required)


Switch to our mobile site