Problem with Virtual Hosts on WAMP
Posted by: jebediah (---.customer.t3.se)
Date: March 19, 2012 12:22AM

Long story short. I followed this giude [blog.jlbn.net] to set up Vitual Hosts.
It work perfect, but only for one site.

For an example.
In the Windows hosts file i've entered
127.0.0.1 localhost
127.0.0.1 site1.dev
127.0.0.1 site2.dev

And in httpd-vhosts i've entered
<VirtualHost *:80>
ServerName site1.dev
ServerAlias site1.dev domain
DocumentRoot C:/temp/wamp/www/site1.dev
ErrorLog "C:/temp/wamp/www/site1.dev/logs/error.log"
CustomLog "C:/temp/wamp/www/site1.dev/logs/access.log" common
</VirtualHost>

<VirtualHost *:80>
ServerName site2.dev
ServerAlias site2.dev domain
DocumentRoot C:/temp/wamp/www/site2.dev
ErrorLog "C:/temp/wamp/www/site2.dev/logs/error.log"
CustomLog "C:/temp/wamp/www/site2.dev/logs/access.log" common
</VirtualHost>

<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/temp/wamp/www
ErrorLog "C:/temp/wamp/www/logs/error.log"
CustomLog "C:/temp/wamp/www/logs/access.log" common
</VirtualHost>

The problem is that it does not matter if i type localhost or site2.dev in the browser, i always ends up on site1.dev

Options: ReplyQuote
Re: Problem with Virtual Hosts on WAMP
Posted by: tfabland (---.hfc.comcastbusiness.net)
Date: March 20, 2012 03:40PM

Why are you in C:/temp?

C:/wamp/www/ is docroot for the localhost and I see no reason to place your vshosts there. As photographer Fred Picker used to say "Different is not the same, only the same is the same".

I set up mine like below. This method more closely follows that of a live server i.e. files that don't have to be in docroot can instead be in the parent directory. On most nix type servers this would be /home/user_name/, with docroot as /home/user_name/www/ or /home/user_name/public_html/.

For example, I use codeigniter and keep all 'system' and 'application' directories and files in say /home/user_name/system/, /home/user_name/application/. On my local test server this would be C:/wamp/directory_name1/system/, C:/wamp/directory_name1/application/. Only those files that HAVE to be web accessible like images, css, js etc, would be placed within /home/user_name/www/ or C:/wamp/directory_name1/www/. PHP is more than capable of pulling in most resources from above docroot.


NameVirtualHost *:80

#######################################################

<VirtualHost *:80>
ServerAdmin me@somewhere.com
DocumentRoot "c:/wamp/wf/www"
ServerName wf
ErrorLog c:/wamp/logs/wf-error_log
CustomLog c:/wamp/logs/wf-access_log common

<Directory c:/wamp/wf/www>
Options +All +MultiViews
AllowOverride All
Allow from all
</Directory>
</VirtualHost>

#######################################################

<VirtualHost *:80>
ServerAdmin me@somewhere.com
DocumentRoot "c:/wamp/fab/www"
ServerName fab
ErrorLog c:/wamp/logs/fab-error_log
CustomLog c:/wamp/logs/fab-access_log common

<Directory c:/wamp/fab/www>
Options +All +MultiViews
AllowOverride All
Allow from all
</Directory>

# I no longer have a need for cgi, but this is how I did it way back when:
#ScriptAlias /cgi-bin/ "c:/wamp/fab/www/cgi-bin/"
#<Directory c:/wamp/fab/www/cgi-bin>
# AddHandler cgi-script cgi pl
# Options +Indexes +FollowSymLinks +Includes +ExecCGI
# AllowOverride All
# Order allow,deny
# Allow from all
#</Directory>
</VirtualHost>

#######################################################

<VirtualHost *:80>
ServerAdmin me@somewhere.com
DocumentRoot "c:/wamp/sb/www"
ServerName sb
ErrorLog c:/wamp/logs/sb-error_log
CustomLog c:/wamp/logs/sb-access_log common

<Directory c:/wamp/sb/www>
Options +All +MultiViews
AllowOverride All
Allow from all
</Directory>
</VirtualHost>

#######################################################
# LEAVE LOCALHOST IN THE LAST POSITION IN FILE
# (Not sure this is "required" but it did solve a past problem for me, but I don't recall what it was smiling smiley
#######################################################

<VirtualHost *:80>
ServerAdmin me@somewhere.com
DocumentRoot "c:/wamp/www"
ServerName localhost
ErrorLog c:/wamp/logs/localhost-error_log
CustomLog c:/wamp/logs/localhost-access_log common

<Directory c:/wamp/www/>
Options +All +MultiViews
AllowOverride All
</Directory>
</VirtualHost>

Options: ReplyQuote
Re: Problem with Virtual Hosts on WAMP
Posted by: jebediah (---.customer.t3.se)
Date: March 21, 2012 12:29AM

tfabland Wrote:
-------------------------------------------------------
> Why are you in C:/temp?

LOL! Could it be that i installed Wamp on C:\Temp\Wamp?

Options: ReplyQuote
Re: Problem with Virtual Hosts on WAMP
Posted by: rob20 (---.dhcp.aldl.mi.charter.com)
Date: March 21, 2012 04:06AM

I read somewhere not to install wamp on drivr C

Since your using virtual hosts, it would be easier to work on your sites if you change to:
(moving sites to root of drive.)

<VirtualHost *:80>
ServerName site1.dev
ServerAlias site1.dev domain
DocumentRoot C:/site1.dev
ErrorLog "C:/site1.dev/logs/error.log"
CustomLog "C:/site1.dev/logs/access.log" common
</VirtualHost>


I had some type of problem with the decimal point in the site name. Can't remember what.

Thanks to all who help.

Options: ReplyQuote


Sorry, only registered users may post in this forum.