icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » Search Me! » [Tutorial] Advanced website testing via the HOSTS file

Search Me! Lots of information is found in this board. You can also ask general questions here if you'd like! This is the last stop on Surmunity.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old March 8th, 2008, 7:09 PM   #1 (permalink)
Searcher
Surpass Staff
 
Kayla's Avatar
 
Joined in May 2003
Lives in Orlando
24,448 posts
Gave thanks: 935
Thanked 783 times
[Tutorial] Advanced website testing via the HOSTS file

Often a web hosting client will signup with a new Surpass Hosting account with the intent of transfering an existing website from another cPanel server over to Surpass Hosting, or designing a new website on the new Surpass 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.
__________________
Follow Surpass on Twitter and Facebook
Check out interesting finds on the Surpass Blog
.... it's coming.


Kayla is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks Kayla for this great post!
Edwin (March 9th, 2008)
Old March 8th, 2008, 11:32 PM   #2 (permalink)
 Macboy
Comfy Contributor
 
deodeep's Avatar
 
Joined in Jun 2007
Lives in Mumbai, India
Hosted on Zeus
141 posts
Gave thanks: 10
Thanked 5 times
Here's how to do the above on Mac OS X

( You'll need root privileges to edit the hosts file )


1. Launch up Terminal


2. Type in the IP and the domain name you want. I am considering the same example used by Kayla above.


3. (Optional) You can add Hashes "#" to comment some line, so Mac OS X does not read it. This is fairly useful if you want to check back the old host. So instead of deleting the whole line, just comment it.


4. To Save, Hit Control X ( ^X )


At the bottom of the Window, it'll ask you whether you are sure you want to save the modified buffer.
Press Y, and then Enter.

5. It'll ask you the path, where to save ?


Just press enter

Thanks
__________________
¿ ɥnɥ 'ʇɐ ƃuıʞool noʎ ǝɹɐ ʇɐɥʍ ¿ ɟʇʍ
deodeep is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks deodeep for this great post!
Dan (March 9th, 2008)
Old March 8th, 2008, 11:59 PM   #3 (permalink)
Surpass Fan
Excelling Contributor
 
cowboy's Avatar
 
Joined in Nov 2005
Lives in Colorado
Hosted on DEDI
934 posts
Gave thanks: 2
Thanked 94 times
Being that this is most beneficial while working with new websites, I suggest also adding ftp.johndoe.com so the ftp client can be setup permanently.
__________________
Where would you be if you were at the highest court in the land (US)?
cowboy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks cowboy for this great post!
Edwin (March 9th, 2008)
Old March 9th, 2008, 4:36 AM   #4 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Hosted on Gojira
8,027 posts
Gave thanks: 48
Thanked 129 times
This can also be used locally with virtualhosts to setup a local dev environment. When I still coded PHP, I would commonly setup routes for domain.tld.test. That way I'd know just from the URL what I was working on.
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 9th, 2008, 4:38 AM   #5 (permalink)
 Macboy
Comfy Contributor
 
deodeep's Avatar
 
Joined in Jun 2007
Lives in Mumbai, India
Hosted on Zeus
141 posts
Gave thanks: 10
Thanked 5 times
Checkout my hosts file. 192.168.2.123 is my local web-server. I've been working on a project on that. Hence, domain.com is included in it.
__________________
¿ ɥnɥ 'ʇɐ ƃuıʞool noʎ ǝɹɐ ʇɐɥʍ ¿ ɟʇʍ
deodeep is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On