Running Multiple Websites on 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 /
This entry was posted in Apache. Bookmark the permalink.

One Response to Running Multiple Websites on Apache

  1. eisabai says:

    Very good tutorial. Two thumbs up!

Leave a Reply