Apache Virtual Hosts I

After I had set up my Windows Me PC with the latest Apache Web Server, installed perl, PHP, MySQL and everything else I needed to make it run like a server - next, I had to make Apache recognise the many different 'websites' I have on my HDD.

The answer was to use Apache's powerful Virtual Host support! However just reading and trying to understand the documentation that came with the Apache install was hard - all that text and no FLASH 6.0!?

Local files and web structure

The problem is I had files for all my websites saved on my HDD, structured exactly the way they were on my webservers. To help you understand what I mean, look at the paths to both my websites, on my C drive -

for www.desilva.biz
path: C:\home\desilva\public_html\all_the_files.*

for gidhelp.com
path: C:\home\gidhelp\public_html\all_the_files.*

Getting to my LOCAL website

Once you've setup and started Apache Web Server, opening your default browser and typing http://localhost/ or will take you to your local web (wherever that may be) - I didn't want that!

I wanted to type http://www.desilva.biz (on my browser) and get to 'www.desilva.biz' website on my pc. Type http://gidhelp.com and get to 'gidhelp.com' web files. Also, to test links between the 2 sites, it was even more important to me that Apache 'knew' the difference!

Apache servername

Apache Web Server will not allow you to just add any ol' hostname and make it work, so no matter what you put into 'servername' in the httpd.conf file, only http://localhost or will work.

Step 1: editing hosts.sam or hosts

Anyway, the first step in getting Apache to handle Virtual Hosts on your Windows 9x PC, is to edit AND rename one file found in your
path: C:\windows
directory - HOSTS (or HOSTS.SAM).

Open the file in Notepad or WordPad and look for this line;

code: localhost

and edit the line to something like this;

code: localhost www.desilva.biz gidhelp.com

You must add at least a space - between each; the ip address, hostname1, hostname2, hostname3, etc. And keep the list in one long line if you must.

If the file you found in
path: C:\windows
was HOSTS, then there's nothing more for you to do. If you found HOSTS.SAM, you have to rename it to HOSTS, before running Apache on your PC.

After surfing your Virtual website (off your PC) and you decide to go online and visit the real http://www.desilva.biz on the WWW, you will have to rename HOSTS back to HOSTS.SAM or you may find "Page Not Found" errors trying to access your websites!

Here's a easy way for you to rename the file often using 2 dos batch files.

Step 2: editing httpd.conf

Now, there is just one more thing to do before you can successfully create virtual hosts on your local computer. Editing the Apache httpd.conf file...


Do you like the new design?



 Don't know