Web development blog from Kolkata(Calcutta),India | Goutamdey.com
 
 
 

Apache Virtual Hosts for Windows

What is Virtualhost.
By using Apache Virtualhost directive an Apache Server can be used for several domains with one or many static IP addresses. And from a web developer’’s perspective it could be very helpfull for setting up multiple local domains for different projects.

The Usablity.
Every web developer wants to check his work before uploading his/her work to the live server. Whether the developer works for his/her own or for an organization it’’s a common and best practise. It is very usefull to see the beta in simulated real life test environment, like testing the static links with TLD names(abcd.com) and testing the dynamic part of the development with it also.
So our requirement #1 comes up as having a facility to test our work against for say goutamdey.com.

The Basics.
When user requests for a document by typing the URL in the browser, domain name server translate the domain name entered to an IP address. The browser then sends the user’’s request to the IP address. As of HTTP 1.1, the browser must also send to the web server the domain name that the user entered; it’’s no longer to be implied. This requirement makes virtual hosting possible.

If Apache has no vhosts, it will use the main server’’s DocumentRoot directory (normally set to C:/Program Files/Apache Group/Apache/htdocs). If Apache has been configured for virtualhosts, it will compare the client’’s request to the ServerName of each vhost with the same IP address and port that the request came in for. The accompanying vhost directives of the first ServerName that matches the client’’s request will be applied.

Within a vhost block–between <VirtualHost> and </VirtualHost> tags in httpd.conf–many directives may be given, but only two are typically required: the ServerName and the DocumentRoot directives. The ServerName directive provides the domain name. The DocumentRoot directive sets the root directory for the domain. If Apache finds a vhost with a ServerName that matches a client request, it will look in the root directory specified by the DocumentRoot directive for files. If it finds what was requested, it will send copies to the client. 

The httpd.conf 

Step -1

NameVirtualHost 127.0.0.1
NameVirtualHost 172.16.2.231

Step - 2

<VirtualHost 127.0.0.1 172.16.2.231:80> 
 ServerName goutamdey.com
 ErrorLog logs/goutamdey.com-error_log
 ServerAlias www*.goutamdey.com 
 DocumentRoot “D:/phpprojects/goutamdey/www”
 <Directory “D:/phpprojects/goutamdey/www”> 
      Options Indexes FollowSymLinks +Includes +ExecCGI
      Options Indexes FollowSymlinks MultiViews +Includes
      AllowOverride none
      Order allow,deny
      Allow from all  
 </Directory>
</VirtualHost>

Step – 3

Edit the yourwindir/system32/drivers/etc/hosts 

127.0.0.1       localhost goutamdey.com

And voila you should get the desired xxx.com in your local system and configure virtualhosts as per your needs.

‘,

About Me

Web aficionado from Kolkata, India. Web evengilist and professional Information Architecht, specialist of User Interface (UI), User Experience (UX), Usability and Interaction Design.
Goutam Dey