Apache VirtualHost how to?

He has: 6 posts

Joined: Aug 2005

I have Apache Running on WinXp. Almost all my project is located under the subdirectory in (example):
http://localhost/project1/
http://localhost/project2/
http://localhost/project3/

What I want is to set up all my project in different host(?):

http://project1/
http://project2/
etc..

How do I do That?
Thank You in advance

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

I assume that you don't want to have localhost in it.

This would require one extra step.

In apache config file (httpd.conf in 'nix);

ServerName project1
DocumentRoot "path_to_directory"

restart apache.

2nd Step
Edit your hosts file by opening Notepad (Start/Accessories),
click file open, change to all files (instead of text), go to C:\WINDOWS\system32\drivers\etc\hosts. Edit the hosts file to contain
IP address project1
Example: 192.168.1.1 project1

You should be able to access this as http://project1 in your browser.

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

He has: 6 posts

Joined: Aug 2005

Thank You mairving

I have changed my httpd.conf below :

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#Listen 80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
<VirtualHost *:80>
   DocumentRoot D:/My_URL/project1
   ServerName project1
</VirtualHost>
'

And my host file as you described;
NOw I can Access my project1 as :
http://project1/

But How to add another project ?
I added one more directory below in httpd.conf

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#Listen 80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
<VirtualHost *:80>
   DocumentRoot D:/My_URL/raisa_new
   ServerName project1
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot D:/My_URL
   ServerName project2
</VirtualHost>
'

and added in host :

127.0.0.1 project1
127.0.0.1 project2
127.0.0.1 localhost
127.0.0.1 remove.it
127.0.0.1 remove.it
127.0.0.1 MicroWeb

But when I accesed http://project2

The page that is displayed is same as http://project1

ThankYou

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

From this thread, uncomment out (remove the #) the NameVirtualHost *:80 and restart Apache.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.