How to Setup More Than One Website in a Single, Local Apache 2.2 Installation (with screenshots!)

June 9, 2008 – 5:44 pm

If you did not understand the post title above, allow me to explain in detail. In this tutorial, I will show you how to setup more than one website in a single Apache 2.2 installation . For example, you can have one imaginary website called www.syahid.com plus another one called www.numbertwo.com in one local Apache web server installation. Actually, you can install and setup as many websites as you want inside your computer!

install-more-than-one-apache-webserver

 

Why on earth do I need this?

There are many usages of this tutorial. One of them is that you may want to run / test many websites locally inside your computer but you don’t want to mess with the website that you have setup and configured previously. Another one is that you may want to test a new version of web-based softwares like Wordpress but want to leave the original version untouched.

 

What technology did you use to achieve this?

I am going to use Apache 2.2 for this tutorial. To achieve the above objective with the least amount of effort possible, I am going to make use of Apache’s name-based virtual servers capability. This means that all those domain/website names will be pointed to a single, local area network IP address.

To make it even simpler, I will be using the loopback IP address - 127.0.0.1 ; so everybody won’t have to worry about having to change their IP address inside their computers.

 

Requirements

You need to have an installed Apache 2.2 server inside your Windows computer. Make sure you can run it successfully and view the website content using a web browser. I already have an imaginary website called www.syahid.com running in a default install location inside the C:\Program Files\Apache Software Foundation\Apache2.2 folder so I am all set.

If you don’t fulfill the above requirement, please complete my tutorial on installing Apache 2.2 on Windows locally first.

 

How To Setup More Than One Website in a Single, Local Apache 2.2 Installation

In the tutorial below, I will setup another website inside my Apache web server. The first one is the already up and running website called www.syahid.com. The second one will be www.numbertwo.com. You can choose to use your own domain name but please tune the steps below to reflect your own chosen name.

Run Apache Web Server and Test First Website

1- Run Apache server. Open your browser window and open your first pre-configured website. In my case, I will open www.syahid.com. Make sure this one works first.

 

Setup Network

2- Open yours hosts file that is located inside C:\windows\system32\drivers\etc\hosts (Windows XP) OR C:\winnt\system32\drivers\etc\hosts (Windows 2000). On the line that begins with the loopback address: 127.0.0.1 ; add the name of your second website at the end of the line. In my case, I add www.numbertwo.com at the end of the line.

apache-name-based-virtual-servers-on-local-012

3- Using the Windows command prompt, ping both domain names and make sure you get replies for each of them.

apache-name-based-virtual-servers-on-local-013

 

Setup Websites Directories

4- Open the root path of your Apache 2.2 installation - in my case: C:\Program Files\Apache Software Foundation\Apache2.2. Open the folder that contains the entire first website’s files e.g. htdocs. Create a new folder inside it and move all of them into the new folder.

apache-name-based-virtual-servers-on-local-002

5- Create a new folder on the same level of the first website folder. Now you will have two folders that represent the two websites that you are going to run simultaneously.

apache-name-based-virtual-servers-on-local-004

6- (optional ) If you try to open the first website again, you will notice that there are some minor glitches / errors. Don’t worry about this.

 

Add Contents For Second Website

7- For the sake of this tutorial, create a simple HTML file and save it as index.html inside the second website folder. You can create your own or use this sample HTML file.

apache-name-based-virtual-servers-on-local-019

apache-name-based-virtual-servers-on-local-025

 

Setup Virtual Hosts

8- Open the httpd-vhosts.conf file inside C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\ folder. Remove or comment all the default file contents.

9- Add these contents to the file and save it. Make sure you change the website names to reflect your own website name and folders. You can see that each website has its own VirtualHost section.

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName
www.syahid.com
DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/syahid
ErrorLog “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/syahid/errorlog”
DirectoryIndex index.html index.php
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName
www.numbertwo.com
DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/numbertwo
ErrorLog “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/numbertwo/errorlog”
DirectoryIndex index.html index.php
</VirtualHost>

apache-name-based-virtual-servers-on-local-022

10- Open your Apache configuration file; httpd.conf that is located inside C:\Program Files\Apache Software Foundation\Apache2.2\conf\ folder. Find and remove the # on the line that says Include /conf/extra/httpd-vhosts.conf . Save this file.

apache-name-based-virtual-servers-on-local-018

 

Test Both Websites

11- Restart your Apache web server.

apache-name-based-virtual-servers-on-local-021

12- Open your web browser. Try to open the first website e.g. www.syahid.com

apache-name-based-virtual-servers-on-local-023

13- Open the second website e.g. www.numbertwo.com

apache-name-based-virtual-servers-on-local-024

 

From now, you can setup and test as many websites as you want. You can add more websites to the above settings by repeating these steps:

  • Create a new folder for the new website inside htdocs (DocumentRoot) folder.
  • Create an index.html file inside the folder.
  • Add the website name at the end of 127.0.0.1 line in hosts file.
  • Make sure you can ping the website using its name.
  • Copy and add a VirtualHost section inside httpd-vhosts.conf file. Tweak the new section to reflect the new website name and folder. Save this file again.
  • Open the website with a browser.

You are done! Thank you for trying my (lengthy!) tutorial!

Tags: , , , ,

Love this post? You may want to subscribe to my RSS feed. Thanks for visiting!

Related Posts:


  1. 12 Responses to “How to Setup More Than One Website in a Single, Local Apache 2.2 Installation (with screenshots!)”

  2. if you get “Access forbidden!” for any one of the domain. just goto httpd.conf file and add this. e.g. you are getting this error for “www.numbertwo.com” and this website location on your HDD is “C:/Apache2.2/htdocs/numbertwo”

    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all

    I hope this will help.

    I am Using XAMPP and using the Apache which comes with XAMPP.

    By Moiz Kiyai on Jun 10, 2008

  3. Quite a interesting and in depth tutorial, will be useful to many people indeed.

    By Keith Dsouza on Jun 10, 2008

  4. is there any way to sepup wp envio locally on my computer
    i am using windows xp

    By Ajay on Jun 11, 2008

  5. @Ajay: There is! Search this site for Wordpress.

    By Syahid A. on Jun 11, 2008

  6. i am not able to get you?

    By ajay on Jun 11, 2008

  7. By Syahid A. on Jun 11, 2008

  8. Why am i getting a dialog box to enter
    in a username and password after installing Apache 2.2 to my local
    desktop? I get this when i try to test it by http://localhost/ . I wanted to test my installation and getting this popup
    dialog box instead. Also, i can’t seem to start the monitor service
    either. It is still a red icon. I had downloaded the Win32 Binary
    including OpenSSL 0.9.8h (MSI Installer) file earlier and installed it
    afterwards. Thanks.

    By Darren on Jun 22, 2008

  9. @Darren: I think you should test this with the normal installer first. You should first have a successful Apache running first and foremost before attempting any https connections via OpenSSL.

    By Syahid A. on Jun 22, 2008

  10. Honestly, i didn’t know which one to download and decided on the 2nd one,but you’re saying to download the 1st one? here is what apache has on the site. i am new to all of this as of yesterday. i will eventually install and learn php and mysql. i discovered your site yesterday and love it. don’t know of any other site like this with screenshots.

    # Win32 Binary without crypto (no mod_ssl) (MSI Installer): apache_2.2.9-win32-x86-no_ssl-r2.msi [PGP] [MD5]
    # Win32 Binary including OpenSSL 0.9.8h (MSI Installer): apache_2.2.9-win32-x86-openssl-0.9.8h-r2.msi [PGP] [MD5]

    By Darren on Jun 23, 2008

  11. great stuff guys….being new to this, all the tutorials I ran into so far is duplication of the same old stuff but you guy have stuff that I never new about ..thank you guy I have already bookmark the site.

    By Lionn on Jul 20, 2008

  12. The two site configuration in windows is excellent. How about one step futher, two sites with two services running so you can stop and start one without affecting the other. Like a dev on port 8080 and user on port 80.

    -Jake

    By Jake on Aug 26, 2008

  13. @Jake: Good idea Jake. This tutorial also allows you to run two or more domains at the same time. Ports is another way of doing it, imho.

    By Syahid A. on Aug 26, 2008

Post a Comment

Clicky Web Analytics