1

OK, I have my wamp installed and simply can't setup my virtual hosts properly.

Here's what I have:

Wamp install dir: F:\wamp

Projects dir: F:\www

# F:\wamp\bin\apache\apache2.4.2\conf\extra\httpd-vhosts.conf
<Directory "F:\www">
    AllowOverride AuthConfig FileInfo Indexes Limit Options
    Order Deny,Allow
    AllowOverride All
    Allow from all
</Directory>

NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
    ServerName localhost
    DocumentRoot "F:\wamp\www"
</VirtualHost>

# Yes, it's a symfony2 project
<VirtualHost 127.0.0.1>
    DocumentRoot "F:\www\my_project\web"
    DirectoryIndex app_dev.php
    ServerName my_project
</VirtualHost>

hosts file from windows is configured and has the necessary: 127.0.0.1 project_name line included.

Apache httpd.conf:

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

Now the browser tells me this, when accessing URL: my_project/

Forbidden
You don't have permission to access / on this server.

Could somebody give me a clue on what's going on here?

Andrei Stalbe
  • 1,511
  • 6
  • 26
  • 44
  • Personally, I would keep the dev site(s) nested in the "f:wamp/www/" directory. Paths needn't have windows style backslashes - forwardslashes suffice. Be sure to include a terminal `/` in each path. Be sure to "Restart All Services" after making changes. – Beetroot-Beetroot Mar 30 '13 at 11:56
  • The `/` at the end of each path actually fails the WAMP to restart all services. I tried both `/` and '\' in my paths and none of them worked. Keeping the projects in my `wamp\www` directory is something I don't really like in case if I want to re-install WAMP Server etc. I would rather go with `F:\wamp\www\my_project` symlinked to `F:\www\my_project`. Thanks for the comment anyway. – Andrei Stalbe Mar 31 '13 at 07:16
  • I thought "symlink" was a UNIX term? – Beetroot-Beetroot Mar 31 '13 at 07:25
  • It does work on Windows too, there is a tool for that `Link Shell Extension`. – Andrei Stalbe Mar 31 '13 at 07:44
  • I would be suspicious that the "symlinking" is something to do with the problem. Try setting up a dummy project in `F:\wamp\www`, see if you can establish a virtual host for it, then try migrating the project out to your preferred location and put a symlink in place. – Beetroot-Beetroot Mar 31 '13 at 07:56
  • The symlink actually solves the problem, it's a workaround though. Setting the virtual host to point a folder inside `F:\wamp\www` even if the folder is a symlink to another folder outside of `F:\wamp\www` works very well. My problem was on how to setup the virtual host to point to an external directory, Apache doesn't have permission to access to other directories, for some reason, Ex: `DocumentRoot F:/www/my_project`. Will go with symlinks method anyway. It isn't exactly what I wanted, but at least it works for now so I can start developing. – Andrei Stalbe Mar 31 '13 at 09:35
  • Aha ok. Just a thought, have you tried specifying `DocumentRoot "F:\www"` in Apache's httpd.conf (in the main server, not in the vhosts)? As far as I know, that's legal. – Beetroot-Beetroot Mar 31 '13 at 16:33
  • Yes, I've tried to setup the `DocumentRoot` in both `httpd.conf` and `v-hosts`, no luck though. – Andrei Stalbe Apr 01 '13 at 14:09
  • I did some background reading on this. It seems that some Windows installations have problems with mapped network drives and some don't, even though all the settings appear to be the same. Nobody knows for certain why. Employment of a symbolic link is understood to be reliable and is recommended so you should probably sick with that. – Beetroot-Beetroot Apr 01 '13 at 15:24
  • Yes, this is one of many downsides of using a Windows workstation for development purposes. – Andrei Stalbe Apr 01 '13 at 19:42
  • 1
    You can see the following blog post for more details... http://stackoverflow.com/questions/15625299/wamp-virtual-host-set-up – Hasib Tarafder Feb 06 '14 at 08:34

1 Answers1

11

Try this as your conf/extra/httpd-vhosts.conf

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


## must be first so the the wamp menu page loads
## and leave as Allow from 127.0.0.1 as outside access should not be required to the wamp homepage
<VirtualHost *:80>
    ServerAdmin webmaster@homemail.net
    DocumentRoot "F:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "F:/wamp/www">
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

# Yes, it's a symfony2 project
<VirtualHost *:80>
    DocumentRoot "F:\www\my_project\web"
    ServerName myproject.dev
    ServerAlias myproject.dev www.myproject.dev
    Options Indexes FollowSymLinks
    <Directory "F:\www\my_project\web">
        AllowOverride All
        Order Deny,Allow
        Allow from 127.0.0.1
        Allow from 192.168.2
        ## change to Allow from all when it works
    </Directory>
</VirtualHost>

Now you need to add the site name(s) to your hosts file like this.

127.0.0.1 myproject.dev 
::1 myproject.dev 

EDIT:

For your browser to find your site domain names you must tell windows that the domain name you are using for testing exists and which ip address it lives on. You do this by adding your testing domain names to a file called hosts. This is read when windows loaded its networking component and cached by a service called DNS Client

To add new local domain names you must edit the windows hosts file

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

And add one line for each of your virtual hosts like this

127.0.0.1  myproject.dev
127.0.0.1  myproject2.dev
127.0.0.1  myproject3.dev
::1  myproject.dev
::1  myproject2.dev
::1  myproject3.dev

Once this is saved, launch a command prompt using Run as Administrator (right click + shift over the Windows command processor icon to show a menu containing the Run as Administrator menu line) and issue these 2 commands to restart the 'DNS Client' service so it picks up your changes. Alternatively just reboot.

net stop dnscache

when that completes

net start dnscache

PS. The double quotes are required as there is a space in the service name!

HOW TO EDIT THE HOSTS FILE

The hosts file is protected by windows, in order to save it you must have Administrator privilages. On Vista/W7/W8 you may think you are an Administrator BUT YOU ARE NOT.

To successfully save the hosts file do this to launch your editor with Admin Privilages.

Locate your editors icon on the desktop or from the Start menus ( notepad will do if you have nothing else ) right click + shift over your chosen editor icon - will show a menu. select "Run As Administrator" from the menu.

Using file -> open Navigate your editor to the c:\windows\system32\drivers\etc\hosts file.

When you have made changes you will now be allowed to save them.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • I used this methond on my PC, but I can't access to the second virtual host, what do you mean with this: "Now you need to add the site name(s) to your hosts file like this. 127.0.0.1 myproject.dev"? Please help. – laviku Jan 24 '14 at 03:05