You are Here: Articles » Setting Up Domains for Local Projects on Windows Apache

Setting Up Domains for Local Projects on Windows Apache

Using the Apache VirtualHost directive and Windows' hosts file to establish domain names for local projects.

Tagged with Domains, Apache, WAMP, Windows and Web Development
Posted on 27/5/07 by Paul Herron

In Apache, the easiest way to set up a project is to declare its directory path as the DocumentRoot in httpd.conf:

  1. # DocumentRoot: The directory out of which you will serve your
  2. # documents. By default, all requests are taken from this directory, but
  3. # symbolic links and aliases may be used to point to other locations.
  4. #
  5. DocumentRoot "C:\Design\myproject"

That directive, after restarting Apache, would make the contents of myproject available at http://localhost/. This is fine for one project, but accessing the contents of a different project directory - say, C:\Design\myotherproject - as if it were the document root would require changing the config file and restarting Apache.

VirtualHost Saves the Day 

In httpd.conf, we can first use the NameVirtualHost directive to specify the IP to which name-based requests will resolve. As we're working locally, this should be the loopback IP address, 127.0.0.1. We then give a series of VirtualHost directives to specify the domain name and corresponding directory for each project.

  1. NameVirtualHost 127.0.0.1
  2.  
  3. <VirtualHost 127.0.0.1>
  4.         DocumentRoot "C:/Design/myproject"
  5.         ServerName myproject.l
  6. </VirtualHost>
  7. <VirtualHost 127.0.0.1>
  8.         DocumentRoot "C:/Design/myotherproject"
  9.         ServerName myotherproject.l
  10. </VirtualHost>

We now need to take care of the DNS part of this process. Requests for any of our test domains should map to 127.0.0.1, and this can be enforced in the Windows hosts file, usually available at C:\WINDOWS\system32\drivers\etc\hosts.

  1. # Copyright (c) 1993-1999 Microsoft Corp.
  2. #
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  4. #
  5. # This file contains the mappings of IP addresses to host names. Each
  6. # entry should be kept on an individual line. The IP address should
  7. # be placed in the first column followed by the corresponding host name.
  8. # The IP address and the host name should be separated by at least one
  9. # space.
  10. #
  11. # Additionally, comments (such as these) may be inserted on individual
  12. # lines or following the machine name denoted by a '#' symbol.
  13. #
  14. # For example:
  15. #
  16. #      102.54.94.97     rhino.acme.com          # source server
  17. #       38.25.63.10     x.acme.com              # x client host
  18.  
  19. 127.0.0.1       localhost
  20. 127.0.0.1       myproject.l
  21. 127.0.0.1       myotherproject.l

All being well, this setup would make the two example projects available at http://myproject.l and http://myotherproject.l.

Apache will need a restart for the changes to take effect. It might also be necessary to restart Windows' DNS Client service, which can be found by right-clicking My Computer, selecting Manage and navigating to the Services section under Services and Applications.

Comments

pierre wrote on 1/6/07:

Thanks Paul, it now works on my local machine !!

cheers 

Elmira wrote on 27/8/11:

Touchdown! That's a rlealy cool way of putting it!

lutvgdc wrote on 27/8/11:

MxbVU8 wgcwgmqrhbnn

morenpark wrote on 4/9/11:

colchicine :PP online pharmacy zovirax =-[

office2010key wrote on 16/11/11:

The Microsoft office 2011 users can Office 2010 work more efficiently with the Microsoft Office 2010 simple and intuitive Download Office 2010 user interface new graphical MS Office 2010 menus and a familiar Office 2010 Key experience provide the Office 2010 Download tools you need to plan and Office 2010 Professional manage your project. And the Microsoft Office 2010 Download tabs and contextual menu buy microsoft office 2010 groupings reveal powerful features, Windows 7 making it easier to get Microsoft Windows 7 started and realize results Win 7. Simply be more productive Download Windows 7 by choosing your own menu Buy Windows 7 options, quick access Office 2007 toolbar settings and Microsoft Office 2007 setting defaults.Enhanced copy Office 2007 Download and paste makes it easy to Office 2007 Professional share information effectively MS Office 2007 with other Office 2007 Key applications while retaining buy microsoft office 2007 formatting. And the added columns Download Office 2007 dynamically by entering Microsoft Office 2007 Professional data without having to first select purchase microsoft office 2007 the data type.

http://softwarestockss.blogspot.com

http://software-stocks.com

54235 wrote on 2/1/12:

Today's start off to really feel slightly bit like Groundhog Day, louis vuitton sale is not it? A few hours ago, we brought to you a story about Louis Vuitton suing a media organization for violating its trademarks, and now we have news of a provider that thinks it is a very good concept to print the visage of an Hermes Birkin on a cheap louis vuitton canvas bag: the V73 Canvas Printed Tote. The day's handbag news is downright retro. you probably could have guessed how this campaign would search louis vuitton speedy sale pale, valuable and ever so sweet. The louis vuitton sale brand tapped Steven Meisel to shoot Daria Strokous and Kati Nescher in the world's most luxurious ice cream shop, and the outcome match the mood in the louis vuitton speedy 25 clothes and accessories perfectly. Check out another shot right after the jump.the Kelly form louis vuitton neverfull MM a straightforward, arm-carried bag having a front flap closure and a major deal withlouis vuitton neverfull is often a traditional form that will not definitely belong to louis vuitton speedy 30 a lot as it belongs to handbag layout in general. Significantly like the louis vuitton luggage, the shape has reached this kind of a classic degree that attributing it to only a single business no longer seems fair. And when the reinterpretations yield bags as unique in the original since thelouis vuitton speedy Postman's Lock Satchel, I believe it is simple to see why I take that opinion 

Leave a Comment

CAPTCHA[Refresh]

« Articles

Article Tags

Show all articles, or just those tagged as:

Feed

The articles RSS feed is available.

Elsewhom

  • Coding My Thoughts.
    Java, PHP, and some other technological mumble jumble. Also, some real-life stuff as well.
  • The Tech.
    MIT's Student Newspaper
  • If Then Else.
    A weblog by Eduardo Sousa, a film and video geek from Porto, Portugal, with a knack for design and a keen interest in the affairs of mankind
  • hackdiary.
    Matt Biddulph's blog
  • bit-tech.net.

See More…

Back to top.