6

I have installed Wamp so I can run a few simple dynamic sites that I built. I want to be able to have three or four and learn how to do things at local level and then upload the improved files to the live site without having to rewrite sections due to different location/paths etc.

To get WampServer index page to show I go to http-vhosts.conf and add

<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "E:/wamp/www"
</VirtualHost>

I understand that I put my site directory labelled mysite.local into the E:wamp/www so the path becomes E:wamp/www/mysite.local. I then go to http-vhosts.conf and add

<VirtualHost *:80>
ServerName mysite.local
DocumentRoot "E:/wamp/www/mysite.local"
</VirtualHost>

my host file has

127.0.0.1       localhost  
127.0.0.1       mysite.local

and my httfp.conf has

# Virtual hosts  
Include conf/extra/httpd-vhosts.conf

So my problem with all this done I get my WampServer index showing fine when I type localhost in the url, and mysite.local appears on that index page under "Your Projects" which is all good, but when I click on the mysite.local link from WampServer, the url changes to localhost/mysite.local not mysite.local, and then when I click a page link from localhost/mysite.local I get localhost/mysite.local/linkedpage as the url and a 404 error.

mysite.local as the url also brings up the WampServer index page

If I comment out ServerName localhost from http-vhosts.conf and restart apache. I get what I'm after when I try mysite.local as the url - mysite works and all the dynamic links work. but the WampServer index is then a 404 error.

All I want to be able to do is log in to WampServer and visit various sites from "Your Projects" list.

Please help a numpty

David
  • 16,246
  • 34
  • 103
  • 162
Peter23
  • 97
  • 2
  • 8
  • 1
    Why use the wampserver 'your projects' list? Just bookmark the various local urls in your browser. Also, probably more suitable to Serverfault. – David Mar 27 '13 at 14:07
  • Thanks David - surprised I haven't had any answers? I just thought it would be good to set it up as it appears to be intedned. I don't know what "more suitable to serverfault means". – Peter23 Mar 27 '13 at 14:46
  • http://serverfault.com/ – David Mar 27 '13 at 15:46

2 Answers2

4

hosts file and httpd.conf look OK.

Some things to try ...

  • <VirtualHost *:80> for both virtual hosts.

  • Make sure DocumentRoot strings have a terminal /.

  • For the root virtual host, ServerName localhost:80.

  • To browse via the virtual hosts, always omit localhost/ from the url. The "Your Projects" links include localhost/ and access projects as paths from the root, not as independent sites, each with its own root (which is what virtual hosts gives you).

  • (WAMP 2) When everything else is fixed ... to bring the "Your Virtual Hosts" section of the root "index.php" page alive , follow these instructions. I just did this and have no regrets. Now I can click links to access my sites served as virtual hosts - yay! Exactly what I always wanted of the "Your Projects" links but didn't get.

BTW, the <VirtualHost>...</VirtualHost> directives are the things that tie each host name to a particular path in the server's file system, so subdirectories in "E:/wamp/www/" don't need the ".local" suffix. After removing ".local" from the dirs themselves, make corresponding changes to the DocumentRoot entries , eg DocumentRoot "E:/wamp/www/mysite/". But be sure to leave ".local" in the "ServerName" entries, eg. ServerName mysite.local, to match the entries in your "hosts" file.

Beetroot-Beetroot
  • 18,022
  • 3
  • 37
  • 44
  • 1
    really sorry for the long delay in replying. I managed without it working correctly and have just tried your suggestion and it worked perfectly :-) I can now view wampserver home page with links to my sites . You are a star. Sadly I cannot give you a vote up as I need 15 reputations? – Peter23 Jun 14 '13 at 11:08
  • Yes, there's something massively satisfying in getting this stuff working. If you feel strongly about accepting/upvoting my answer then you can bookmark the page and return when you have a bit more rep. – Beetroot-Beetroot Jun 14 '13 at 12:02
2

See below for a sensible vhosts definition

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


## must be first so the the wamp menu page loads
<VirtualHost *:80>
    ServerAdmin webmaster@homemail.net
    DocumentRoot "D:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "D:/wamp/www">
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@homemail.net
    DocumentRoot "D:/websrc/www/project1"
    ServerName project1.dev
    ServerAlias project1.dev www.project1.dev
    Options Indexes FollowSymLinks
    <Directory "D:/websrc/www/project1">
        AllowOverride All
        Order Deny,Allow
        Allow from 127.0.0.1
        Allow from 192.168.2
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@homemail.net
    DocumentRoot "D:/websrc/www/project2"
    ServerName project2.dev
    ServerAlias project2.dev www.project2.dev
    Options Indexes FollowSymLinks
    <Directory "D:/websrc/www/project2">
        AllowOverride All
        Order Deny,Allow
        Allow from 127.0.0.1
        Allow from 192.168.2
    </Directory>
</VirtualHost>

You will have to change the directory names to fit your situation.

Also remember to add your vhosts names to your HOSTS file

c:\windows\system32\drivers\etc\hosts

> 127.0.0.1 project1.dev
> 127.0.0.1 project2.dev

Virtual hosts are best setup somewhere outside the /wamp/www folder structure, in my opinion. See above in the example I have used d:\websrc\www\project1

You run a virtual hosts using project1.dev keyed directly into the browser address field.

If you want to see your virtual hosts on the wamp home page do the following:

create a folder ?:/wamp/vhosts In that folder create files named as follows: project1.dev.conf project2.dev.conf ... etc

They do not require any content, just the correct name to match you virtual hosts names

These will then show on the wamp home page under a TITLE of Your Virtual Hosts and you can click on them to launch them.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149