Creating Virtual Domains Under Apache
When Apache is installed on a M.S. Windows XP / Vista computer the Apache installer places Apache’s file structure in:
C:\Program Files\Apache Group\Apache2
Apache’s index file, which is displayed when http://localhost is typed into a Browser window and the Go button or the Enter key is pressed, resides in:
C:\Program Files\Apache Group\Apache2\htdocs
If you do not want Apaches default index page to be displayed when http://localhost is typed in a Browser’s address bar and the Go button or the Enter key is pressed, simply create your own HTML file, name it index.html and place this in:
C:\Program Files\Apache Group\Apache2\htdocs
Now if you enter http://localhost in a Browser’s address bar and press Go or the Enter key your HTML page will be rendered in the Browser’s window.
This is an indication that Apache is working perfectly.
Having said that, it’s definitely not good practice to place all your website’s resources within the folder that Apache uses for its own resources i.e.:
C:\Program Files\Apache Group\Apache2\htdocs
It’s good programming practice to keep your website’s resources separate from Apache’s internal resources.
All that is required is that you create a separate folder, anywhere on your hard disk and place your website resources within that folder.
For example: d:\mysite
Now all that remains is that Apache needs to be informed that the folderd:\mysite is where you’ve loaded all your website’s resources.
You do this by creating a Virtual Domain under Apache and binding this domain to the folder where your website’s resources are placed.
To create a virtual domain you have to make changes within Apache’s httpd.conf file.
Apache’s httpd.conf file is resides in:
C:\Program Files\Apache Group\Apache2\conf
Navigate to that folder and the first thing to do is to make a copy of Apache’s httd.conf file and save this within Apache’s conf folder i.e. httpd_copy.conf.
This way if you’ve made some errors when adding a virtual domain to the httpd.conf file and Apache stops working, all you have to do is to overwrite Apache’s httpd.conf file with the copy you’ve made, then ensure that the file is re-named httpd.conf and Apache should start up again.
NOTE: In case you do not keep a copy of Apache’s httpd.conf and you’ve damaged the original httpd.conf file you have to re-install Apache from scratch, to get a working copy of Apache web server.
Now open the httpd.conf file in your favorite ASCII editor, (Notepad would do just fine). Scroll right down to the end of the httpd.conf file and you will notice Apache’s virtual domain example.
The code there should look something like:
#NameVirtualHost *:80
#VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#
#
The NameVirtualHost and VirtualHost directives are what we are interested in.
Simply copy the whole lot from # NameVirtualHost to and paste this below the original code.
Then delete the # which appears before each entry as shown below.
Please notice the section where the # are not deleted.
NameVirtualHost *:80
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
Next:
Change
NameVirtualHost *:80
To read as:
NameVirtualHost 127.0.0.1:80
Notice that the # has been deleted
And
The local host ip 127.0.0.1 has replaced the * in this entry
Now let’s take a look at the
ServerAdmin ivan@ivanbayross.com
DocumentRoot d:\mysite
ServerName www.mysite.com
ErrorLog d:\mysite\errors\errorlog
Notice that the:
ServerAdmin has a legitimate Email ID bound to it.
DoumentRoot has the physical path to your websites resources
ServerName can have any name bound to it, I’ve chosen www.mysite.com
ErrorLog has the path to where Apache can keep its error log file
NOTE: Do not forget to create the folder d:\mysite\errors. Then using Notepad create an empty file named errorlog within this folder. Please notice the absence of any file extension.
Save the httpd.conf you’ve been editing and re-start Apache.
To restart Apache simply right click on the
icon in the task bar and a popup window will appear as shown in diagram 1.
![]() |
| Diagram 1 |
Click on Open Apache Monitor and a popup window will appear as shown in diagram 2
![]() |
| Diagram 2 |
Simply click the Restart button. If all is well Apache will startup perfectly.
There’s a few more steps to be carried out to check is you’ve created the Virtual domain correctly, they are:
Making an entry in the hosts file.
Using the file Browser navigate to the folder C:\Windows\System32\drivers\etc
Within this folder there will be a file called hosts.
NOTE: If you have never used the hosts file ever before then you will find a file called hosts.sam or hosts.tmp in this folder. Copy this file to a file named hosts and you are done. Then edit the contents of hosts as indicated below.
# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client
NOTE: Between the ip and the site name you must use the Tab key.
# For example:
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0. www.mysite.com
Save hosts and exit.
Finally place a unique index.html file within the folder d:\mysite. Now when you enter the URL in the Browser address bar: http://www.mysite.com Apache will display the contents of the index.html file you’ve place in the folder d:\mysite.
If all this works perfectly then you can build the rest of your website within the folder d:\mysite
Installing Apache web server on XP
This tutorial shows you how to install Apache on any computer running Windows XP / Vista 32 bit.
Prior installing Apache it’s necessary to get its executable from:
On entering the URL into the Browser’s address bar and clicking Go or pressing the Enter key the page as shown in diagram 1 will be rendered in the Browser.
![]() |
|
Diagram 1. |
When Apache’s home page loads take a look at its right hand side and locate the link HTTP Server. On click of the HTTP server link the page as shown in diagram 2 is rendered in the Browser.
![]() |
|
Diagram 2. |
Locate the Download link in the Apache 2.X.X Released as shown in diagram 2. On click of this link the page as shown in diagram 3 is rendered in the Browser.
![]() |
|
Diagram 3. |
From the Win32Source select the Apache binary that you desire. The choices available are expanded briefly in table 1.
Choices available for Apache Binaries:
| Win32 Source | |
| 1 | Win32 Binary without crypto (no mod_ssl) (MSI Installer) |
| 2 | Win32 Binary including OpenSSL 0.9.8h (MSI Installer) |
Table 1.
Any of the above binaries will load successfully on Windows XP. If you want to play only with Apache then the Win 32 source should be just fine, i.e. option 1.
If you want to play with Apache and use SSL then choose Win32 Binary including OpenSSL 0.9.8h (MSI Installer) i.e. option 2
I am using Firefox as my Browser of choice, hence On click of either option 1 or 2 the file download window pops up as shown in diagram 3.
![]() |
|
Diagram 4. |
Click the File Save button and save the Apache binary chosen to an appropriate subdirectory on the hard disk.
For example c:\webserver.
Installing Apache:
Navigate to the previously created folder (c:\webserver) and double click the Apache executable file in that folder. This will start the installation of Apache web server on the computer. Simply follow the instructions shown by the installer:
The first screen that renders in the Browser On click of Apache’s executable is as shown in diagram 5.
![]() |
|
Diagram 5. |
Click Next
Select ‘I accept terms in the license agreement’ radio button as shown in diagram 6. Click Next.
![]() |
|
Diagram 6. |
Click Next.
The screen as shown in diagram 7 renders in the Browser.
![]() |
|
Diagram 7. |
Click Next. The screen as shown in diagram 8 renders in the Browser
![]() |
|
Diagram 8. |
In the Network Domain text box type in localhost
In the Server Name text box type in localhost
In the Administrators Email Address text box type in a legitimate Email address to which Apache can send messages to. We’ve used info@localhost. We have a mail box on the hosting server with the same name. Click Next. The screen as shown in diagram 9 is rendered in the Browser.
![]() |
|
Diagram 9. |
Select Custom and click Next. The screen as shown in diagram 10 is rendered in the Browser
![]() |
|
Diagram 10. |
Because we want our server to be installed in c:\webserver click Change to change inform Apache’s installer where you want Apache’s installation to be done. The screen as shown in diagram 11 is rendered in the Browser.
![]() |
|
Diagram 11. |
Navigate to C:\webserver and then click OK. The screen as shown in diagram 12 is rendered in the Browser. Click Next.
![]() |
|
Diagram 12. |
Apache’s installer has collected all the information it needs to successfully install Apache on the computer. Click Next to begin the Apache’s install process. After the install process completes the screen as shown in diagram 13 is rendered in the Browser indicating that Apache has been successfully installed on the computer.
![]() |
|
Diagram 13. |
Click Finish to complete Apache’s install process. You should notice a small icon in the system tray as shown in diagram 14.
![]() |
|
Diagram 14. |
Testing Apache’s Installation
Type in the URL http://localhost in the Browser’s address bar and press Go or Enter. The screen as shown in diagram 15 should render in the Browser indicating that Apache has been installed correctly.
![]() |
|
Diagram 15. |
Apache has been installed successfully and is running perfectly on your computer





























