Setting up a virtual host is a must; you need the ability to test products locally. Testing on a live website can quite often become time-consuming and confusing. It is very easy to setup your computer to act as a virtual host or web server. Even easier it is to allow your web server to act as a dedicated server for multiple websites.
What are advantages of setting up a virtual host:
- build websites before publishing
- match local and remote sever settings
- test before going live
You should have an installation of PHP, MySQL and Apache running on your computer. I use AppServ which installs and sets up everything for me. Another option is XAMPP. By default the root server is located at http://localhost. Straight out of the box this is great for someone who is working on one website. We want more. I have a virtual host for eight sites – three of which are live, others are for testing different setups.
Open Apache’s httpd.conf file. Look for the section “Virtual host” which should be commented out. I added the following code for my base installation of AppServ:
ServerAdmin myname@email.com ServerName localhost.com DocumentRoot "C:/AppServ/www/"
The DocumentRoot is my default for AppServ. I set the ServerName to localhost.com. Whenever I want to access AppServ I will use the URL http://localhost.com. I chose this because in AppServ’s index file I have each virtual host/website linked here allowing quicker access.
For my personal blog I also set up a virtual host by entering the following below the following code:
ServerAdmin myemail@email.com ServerName localhost.timtrice.com DocumentRoot "C:/AppServ/www/timtrice/"
Notice the only changes I’ve made were my ServerName, which now is set up like a subdomain, and my DocumentRoot. All of my Wordpress files that operate this website are in the DocumentRoot directory.
Next, instruct Windows to understand the URL’s are not internet websites, but intranet – our local computer. Find the file named “hosts” (no extension) located at C:\Windows\System32\drivers\etc. Open this file using Notepad. You should see several lines commented out by the pound sign (#) and then something similar to below:
127.0.0.1 localhost
Append your new virtual host information. For me, I just added the .com to localhost and then added my personal blog testing site, localhost.timtrice.com and assigned the same IP address.
127.0.0.1 localhost.com 127.0.0.1 localhost.timtrice.com
Save the file, close and restart Apache. Type in either of the two URL’s into your browser to be taken to your virtual host homepage. Even though my personal blog files are located in a subdirectory of AppServ, Apache treats those two directories as different websites.
Setting up a virtual host will make life so much easier. It’s very easy to get lost trying to build multiple websites off one root website and you will inevitable come to problems. Furthermore, matching a virtual host to a live website will help ensure updates go smoother without errors.
{ 1 comment… read it below or add one }
I am using vista for over a year now, still not okey with it. I surely miss XP. Anyway looking forward for SP2 to be released.