alexjc, I missed this the first time around. (thanks for pulling it back up David). Let's start back here:
First, create yourself a "apacheon.bat" and "apacheoff.bat" that will turn on and off apache. Make a icon on the desktop or start menu to them (change paths to suit your system):
--- ApacheOn.bat
@rem remove the old file
del c:\windows\hosts
@rem install new
copy c:\windows\hosts.loc c:\windows\hosts
@rem lets go apache
c:\apache\apache.exe
rem done
----ApacheOFF.bat
@rem remove the old file
cd c:\Apache
apache -k shutdown
del c:\windows\hosts
@rem install new
copy c:\windows\hosts.net c:\windows\hosts
rem del c:\Apache\logs\httpd.pid
----------------------
To explain: The apacheon.bat installs a new "hosts" file in your windows directory. The new hosts file will contain domain name to IP resolution that will point at your apache setup.
Create a file "hosts.loc" (which is short for hosts.local) that contains your domain names (we'll get to how to setup apache to deal with this in a minute).
First an example local hosts file:
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
127.0.0.15 www.webmasterworld.com
127.0.0.11 www.searchengineworld.com [searchengineworld.com]
127.0.0.9 www.team-mp3.com [teammp3.com]
127.0.0.22 phdss.com
127.0.0.2 showcase.netins.net
127.0.0.4 www.joefarmer.com
127.0.0.5 www.temp.com
127.0.0.10 www.cgi.com
127.0.0.12 www.newsraid.com [newsraid.com]
127.0.0.13 www.traxis.com
127.0.0.14 www.collective.com
127.0.0.20 www.netins.net
So, we kick on apache with the "apachon.bat", and it copies the "hosts.loc" file to "hosts" file. The hosts file is a core domain <-> ip translation that browsers look to first. How do we make apache recognize those as our domains and return content to the browser?
We do it by setting up virtual hosts in the apache httpd.conf file:
<VirtualHost 127.0.0.15>
DocumentRoot /ww/webmasterworld
ServerName www.webmasterworld.com
ServerAdmin foo@webmasterworld.com
ScriptAlias /cgi-bin /ww/webmasterworld/cgi-bin
TransferLog logs/WebmasterWorld-access.log
ScriptLog logs/WebmasterWorld-scripterror.log
LogLevel debug
</VirtualHost>
The first line tells apache on what IP it should respond. Look up at the hosts.loc file. Notice the IP number? Now when we connect to webmasterworld.com from the browser, it requests it from 127.0.0.15. Apache is listening on that ip, and responds with the website specified in the virtual host config.
Create a virtual host for each of your sites. Make your local directories, identical to your online directories - and you are in like flynn.
---
To turn if off, we need to put back a clean hosts file, and shut off Apache. The apacheoff.bat file, over writes your host file with a clean hosts file. Before you ever start, make a backup copy of your current \windows\hosts file to "hosts.net". That will be your "keeper" hosts file that will always be clean.
Caveats:
I've yet to figure out how to get IE to "uncache" the domain<->ip resolution. That means if you hit a website the ip is resolved until the next reboot.
However! Opera will resolve the ip<->domain name each time it is started. So you can run local site, turn off Apache, restart Opera - and your in like flynn (not that I actually know who Flynn was).
The big Recap:
Create the two batch files show above and make shortcuts from your desk top to them named apacheon and apacheoff.
Create a backup of your current \windows\hosts file to \windows\hosts.net
Create a new hosts file called "\windows\hosts.loc" that contains your virtual site ip to domain name resolution.
Create your Virtual Hosts in your apache httpd.conf file.
This is all good for windows 9X/ME.