Running Multiple Websites on Apache

Posted by Robert Love on July 1, 2007 in Apache

You’ve been creating websites on your Apache installation on Windows - making a sub-directory for each site you want to design/develop. But wouldn’t it be good if you could run multiple websites on a single Apache installation - changing http://localhost/mynewsite1/, http://localhost/mynewsite2/, etc. to http://mynewsite1/, http://mynewsite2/, etc. Well you can! - with Apache Virtual Hosts. This article will show you how to run as many websites (or Virtual Hosts) as you like on your Apache installation on Windows by making a few simple additions to your Apache configuration file and your Windows hosts file.

What We’ll Assume

  • You have a working installation of Apache 2.2.4 on Windows (if not, take a look at Installing Apache, MySQL and PHP on Windows).
  • Your Apache DocumentRoot - where your local website files are - is in the default location of C:\Program Files\Apache Software Foundation\Apache2.2\htdocs (if not, simply replace all occurrences of C:/Program Files/Apache Software Foundation/Apache2.2/htdocs with whatever your DocumentRoot is - e.g. C:\www).

Let’s Get On With It

  1. Create a new folder C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mynewsite

  2. Go to Start > Programs > Apache HTTP Server 2.2.4 > Configure Apache Server > Edit the Apache httpd.conf Configuration File

    The Apache configuration file opens (httpd.conf)

  3. Add this line at the very bottom of the file:

    NameVirtualHost localhost

    Apache will now allow multiple Virtual Hosts to run under localhost

  4. Directly under the last line you added in httpd.conf, add the following VirtualHost directive:

    <VirtualHost localhost>
        DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/mynewsite"
        ServerName mynewsite
    </VirtualHost>
  5. Save and close httpd.conf

  6. Open C:\WINDOWS\system32\drivers\etc\hosts in Notepad

    Your Windows hosts file opens

  7. You should see this line somewhere in the file:

    127.0.0.1	localhost
  8. Directly below this line, add the following:

    127.0.0.1	mynewsite
  9. Save and close hosts
  10. Go to Start > Programs > Apache HTTP Server 2.2.4 > Control Apache Server > Restart
  11. Open mynewsite in your web browser (http://mynewsite/)
  12. If all went well, your browser will show a page with Index of /

1 Comment on Running Multiple Websites on Apache

By eisabai on March 10, 2007 at 4:20 pm

Very good tutorial. Two thumbs up!

Comment

Log in or Register to post a comment.

More

Read more posts by Robert Love

About the Author

I'm a web technologist, University lecturer and trainer based in Sydney, Australia. I'm particularly interested in standards-based web design and development using web standards such as XHTML, CSS and the DOM, and open-source software such as Linux, Apache, MySQL and PHP. When I'm not making websites, I like to tell other people how I think they should make websites. I have developed, and teach, a few training courses in web technologies offered through Learn4Life at The University of New South Wales, Sydney, Australia. I'm a member of the W3C HTML Working Group, the Web Industry Professionals Association and the Web Standards Group and can be found espousing my opinions on forums and in mailing lists. My wife and son enjoy the benefits of my full-time employment as Senior Developer with News Digital Media, and they wouldn't mind at all if you wanted to contact me with yet a further opportunity for me to get no sleep.

Installing Apache, MySQL and PHP on Windows How to Become a Web Developer and Make Lots of Money