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
-
Create a new folder C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mynewsite
-
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)
-
Add this line at the very bottom of the file:
NameVirtualHost localhost
Apache will now allow multiple Virtual Hosts to run under localhost
-
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> -
Save and close httpd.conf
-
Open C:\WINDOWS\system32\drivers\etc\hosts in Notepad
Your Windows hosts file opens
-
You should see this line somewhere in the file:
127.0.0.1 localhost
-
Directly below this line, add the following:
127.0.0.1 mynewsite
- Save and close hosts
- Go to Start > Programs > Apache HTTP Server 2.2.4 > Control Apache Server > Restart
- Open mynewsite in your web browser (http://mynewsite/)
- 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.