1

My vhosts are:

# for localhost to work properly
<VirtualHost *:1983>
  ServerAdmin admin@localhost
  DocumentRoot "d:/wamp/www"
  ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)

# afm : Agile Farm Manager
#<VirtualHost *:1983>
#    DocumentRoot "D:/projects/afm/Code"
#    ServerName  dafm.dev
#    <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
#    </Directory>
#</VirtualHost>

# mrs : Meeting Request System
<VirtualHost mrs.dev:1983>
    DocumentRoot "D:/wamp/www/mrs_site/mrs"
    ServerName  mrs.dev
    ServerAlias mrs.dev
    <Directory "D:/wamp/www/mrs_site/mrs">
 Order allow,deny
 Allow from all
 AllowOverride All
    </Directory>
</VirtualHost>

# dtk : Kit Designer
<VirtualHost dtk.dev:1983>
    DocumentRoot "D:/wamp/www/designertoolkit/"
    ServerName  dtk.dev
    ServerAlias dtk.dev
    <Directory "D:/wamp/www/designertoolkit/">
 Order allow,deny
 Allow from all
 AllowOverride All
    </Directory>
</VirtualHost>

And my windows' hosts file has the following mappings

#VIRTUAL DOMAINS

127.0.0.1   dafm.dev
127.0.0.1   mrs.dev
127.0.0.1   dtk.dev

My configured port is :1983 so i access wamp like: http://localhost:1983/

or http://mrs.dev:1983/ goes to my current project. but my other projects are not accessible anymore.

like when i go to dtk.dev:1983/ goes to same project http://mrs.dev:1983/ for every valid request to wamp server.

I need to run multiple projects on WAMP simultaneously. What is the problem with the Virtual Hosts?

please help

Ronnie Depp
  • 159
  • 3
  • 12
  • I've also enabled `vhost_alias_module` for wamp already according to these links: - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf # - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/ # - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope) – Ronnie Depp Dec 02 '14 at 08:29

2 Answers2

4

You need to use NameVirtualHost. See Apache manual: http://httpd.apache.org/docs/current/vhosts/name-based.html

Like this:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Maybe this is working:

NameVirtualHost *:1983

# for localhost to work properly
<VirtualHost *:1983>
  ServerAdmin admin@localhost
  DocumentRoot "d:/wamp/www"
  ServerName localhost
</VirtualHost>

# mrs : Meeting Request System
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/mrs_site/mrs"
    ServerName  mrs.dev
    ServerAlias mrs.dev
</VirtualHost>

# dtk : Kit Designer
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/designertoolkit/"
    ServerName  dtk.dev
    ServerAlias dtk.dev
</VirtualHost>

<Directory "D:/wamp/www/designertoolkit/">
    Order allow,deny
    Allow from all
    AllowOverride All
</Directory>

<Directory "D:/wamp/www/mrs_site/mrs">
     Order allow,deny
     Allow from all
     AllowOverride All
</Directory>
LucasF
  • 883
  • 1
  • 6
  • 17
  • You're right about `NameVirtualHost` directive, but it must be repeated before every `` definition. Below Im gonna post the Answer and New Working Code. – Ronnie Depp Dec 02 '14 at 13:23
  • Did you test the config I posted? I am very sure that it will work this way. – LucasF Dec 02 '14 at 14:37
  • If you use my config you do not need to add `NameVirtualHost` directive for every vhost. `NameVirtualHost` will define the given IP address for use with named vhosts. See here: http://httpd.apache.org/docs/current/mod/core.html#namevirtualhost Using DNS names in `NameVirtualHost` is not recommended. – LucasF Dec 02 '14 at 14:52
  • i tested your config first, but didn't work. So i started looking for a hack of my own. And it worked the magic. i'm running Windows 7 Ultimate & WAMP. Although WAMP, MAMP, LAMP or XAMPP does not matter as these are the basic Apache Directives. – Ronnie Depp Dec 03 '14 at 08:29
  • My purpose is to be able to run/access multiple projects on my single localhost installation of *AMP via creating a named `vhost` for every project for easy testing. So that's what I've accomplished through my own hack. But I still thank you, @LucasF as you pointed me to use `NameVirtualHost` directive in the first place. – Ronnie Depp Dec 03 '14 at 08:33
-3

Thanks to the anonymous @user4311956's answer for pointing out that the NameVirtualHost directive is important.

But with my own testing I found out that if I mention NameVirtualHost directive before each Virtual Host i create it works, fails otherwise.

here the code for httpd-vhosts.conf file that worked the magic:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:1983

# for localhost to work properly
<VirtualHost *:1983>
  ServerAdmin admin@localhost
  DocumentRoot "d:/wamp/www"
  ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)

# afm : Agile Farm Manager
#<VirtualHost *:1983>
#    DocumentRoot "D:/projects/afm/Code"
#    ServerName  dafm.dev
#    <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
#    </Directory>
#</VirtualHost>
NameVirtualHost mrs.dev:1983
# mrs : Meeting Request System
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/mrs_site/mrs"
    ServerName  mrs.dev
</VirtualHost>
NameVirtualHost dtk.dev:1983
# dtk : Kit Designer
<VirtualHost *:1983>
    DocumentRoot "D:/wamp/www/designertoolkit/"
    ServerName  dtk.dev
</VirtualHost>

Thanks again to @user4311956's answer for pointing me in right direction.

Ronnie Depp
  • 159
  • 3
  • 12
  • You should only need the `` parameter once. In fact if you are using Apache 2.4.x it is not actually a valid parameter anymore. – RiggsFolly Dec 02 '14 at 15:19
  • **Mine Server is Running:** Windows 7 Ultimate Apache Version : 2.2.22 PHP Version : 5.4.3 however I needed to work out a way to configure my Local Server to run multiple projects via Named Virtual Host for each project. So I've accomplished what I was looking for. So it doesn't matter what config is recommended & which is not. I tested so many configs before posting to StackOveflow. – Ronnie Depp Dec 03 '14 at 08:52
  • -- With this `config` of mine posted above, I can access project `dtk` by url `http://localhost:1983/designertoolkit/` as well as with this virtual host `http://dtk.dev:1983` – Ronnie Depp Dec 03 '14 at 08:52