Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Local Development

Setting up apache to handle a domain offline



2:14 pm on Jul 6, 2001 (gmt 0)

10+ Year Member

Hi folks,

I've setup a local apache web-server with php, mysql and perl... it's all working nicely and a very nice platform for local development.

However, I'd like to be able to point my browser to mydomain.com, and have it find the files on ... Do i need some sort of local DNS for that? I looked into apache's VirtualServers, but that doesn't seem to be what I need.

Sorry for the simple question, I feel this is something I should know to do!



5:28 pm on Jul 6, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Alex, are you on a *nix or windows machine?

On windows, find a file named "hosts" in the "windows" directory and add your host name(s) with the localhost address, if you don't have a "hosts" file, then you will have to create one using a text editor. Use "HOSTS.SAM" also in the windows directory as an example (you can open it with notepad).

On *nix edit the file /etc/hosts and add "mydomain.com" with, leaving the other entries intact.

In case you decide to add other hosts to your set up:
With name based hosting in Apache you can have multiple domains all with, if that is the case, just keep adding them to the "hosts" file and Apache will present the appropriate site based on the domain name entered. So you could have mydomain.com, mydomain1.com, mydomain2.com, etc. defined in virtual host containers and as long as you have entries in DNS or a "hosts" file the correct sites are displayed.

Have fun!


1:26 pm on Jul 13, 2001 (gmt 0)

10+ Year Member

Yeah, windows... i realised too late ;)

That worked great! You're a star :P



9:39 pm on Jul 18, 2001 (gmt 0)

10+ Year Member

I thought about doing this for some time. Well I finally got around to setting it up.

What a time saver!

If you have thought about it, it is more then worth it.


10:09 pm on Jul 18, 2001 (gmt 0)

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

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
rem done

@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:
# rhino.acme.com # source server
# x.acme.com # x client host localhost www.webmasterworld.com www.searchengineworld.com [searchengineworld.com] www.team-mp3.com [teammp3.com] phdss.com showcase.netins.net www.joefarmer.com www.temp.com www.cgi.com www.newsraid.com [newsraid.com] www.traxis.com www.collective.com 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:

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

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 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.

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.


10:42 pm on Jul 18, 2001 (gmt 0)

10+ Year Member

Thanks Brett,

I am going to set that up tonight. I have a question that I haven't tried to figure out yet but here it is.

Netscape 6.0 will not load on my windows machine if Apache is running. Its like it hangs there waiting for apache to go away. If I shut down apache Netscape 6 loads right up. If I then start apache both run together fine.


11:38 am on Jul 19, 2001 (gmt 0)

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

What does ie or Moz do?


1:42 pm on Jul 19, 2001 (gmt 0)

10+ Year Member

I can open and close all other browsers with apache running. With Netscape 6 when I click to open it nothing happens. Then when I close apache netscape loads from the earlier click. Its like it is waiting in que for apache to close.


2:17 pm on Jul 19, 2001 (gmt 0)

WebmasterWorld Administrator brett_tabke is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Sounds like it is trying to 'phone home to the mothership' and failing. Got me on that one. I've not felt the need to install nn6.


10:17 am on Jul 20, 2001 (gmt 0)

10+ Year Member

Many thanks Brett... i actually read up on the apache configuration, and managed to do that myself. Getting my machine to resolve the server was the problem.

Anyway, this'll come in really handy when I actually own the domain :P I guess at this late stage of development, I should really register it!!

A single hosts file will do until then...

Alex ;)


Featured Threads

Hot Threads This Week

Hot Threads This Month