1

I am on Windows 8 and just now installed Wamp 2.5 (Apache 2.4.9) at C:/wamp to test my code locally. I have my source code repository at D:/workpace/project1 which I manage using GIT (GIT is one of the reasons I don't want to disturb its location).

After Installing Wamp, I just went on to enable virtual hosts by uncommenting the following line in httpd.conf.

 #Include conf/extra/httpd-vhosts.conf

Then I headed to conf/extra/httpd-vhosts.conf created its backup and created the virtual host.

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot "D:/workspace/project1/"
    ServerName project1
    ServerAlias p1
    ErrorLog "logs/project1(local)-error.log"
    CustomLog "logs/project1(local)-access.log" common
    <Directory "D:/workspace/project1/">
        Require all granted
    </Directory>
</VirtualHost>

Also edited the hosts file and added the necessary lines.

127.0.0.1       project1
127.0.0.1       p1

The problem is that I get 403 Forbidden error not just when I access project1/ and p1/, but also when I access localhost/.

When I disable httpd-vhosts.conf in httpd.conf by commenting out,

    Include conf/extra/httpd-vhosts.conf

I am able to access localhost/ but as expected, project1/ and p1/ too resolve to localhost/.

Surprisingly, when I re-enable httpd-vhosts.conf in httpd.conf and restore the backup of original(unchanged) httpd-vhosts.conf, I still get 403 (Forbidden) even on localhost/. But again when I disable httpd-vhosts.conf, localhost/ comes to normal.

It is furthermore surprising to note that If I change DocumentRoot to a dummy folder within c:/wamp/www, the story is the same. So this is not just happening when DocumentRoot is outside c:/wamp/www.

I feel that I have something extra to enable because there is no chance I have messed up anything as this is a fresh installation and I have made no changes except the ones above.

What may be the reason Apache is not getting along with virtual hosts?

Tabrez Ahmed
  • 2,830
  • 6
  • 31
  • 48
  • Just a side note: why using virtual hosts locally? Just create an `Alias` for each project and your are fine. Also no adjustment to the hosts file required... – arkascha May 30 '15 at 08:27
  • For the virtual host issue itself: first step _always_ is to look into the http servers error log file, especially during restart time. That is where the server logs issues with its configuration. Also monitor that file while making requests, you might find additional information about issues. Do you find any additional information that might help with your problem? – arkascha May 30 '15 at 08:28
  • @arkascha, Strange !!! ... The logs are not getting updated when `httpd-vhosts.conf` enabled ... `project1(local)-error.log` and `project1(local)-access.log` too are not created. – Tabrez Ahmed May 30 '15 at 08:41
  • Ah, then most likely the name resolution does not work and your browser tries to access whatever. Check that first, easiest by using the telnet utility: `telnet project1 80` - what happens? – arkascha May 30 '15 at 08:42
  • @arkascha, Where do I look for it ... ? I have update `hosts` file... – Tabrez Ahmed May 30 '15 at 08:44
  • Said so above... Apart from that, just to be _really_ sure: you really, really, really did restart the http server after doing the modifications? And also, again just to be sure, remove those brackets (`(`/`)`) from the log file names in your configuration... – arkascha May 30 '15 at 08:44
  • @arkascha pinging gave a positive reply ... `telnet project1 80` gave an empty screen screen and a blinking cursor for a few seconds before returning to prompt... – Tabrez Ahmed May 30 '15 at 08:52
  • OK, looks like `telnet` cannot connect, which matches your observation that no log files are created. The `ping` command is more or less useless for such things. Could it be that the http server simply does not start with that configuration of yours? but that should be logged into the error log file. Note: the normal error log file of your http server, not that you expect for those virtual hosts. – arkascha May 30 '15 at 08:54
  • @arkascha, No, without httpserver starting, how wud I even get an error? – Tabrez Ahmed May 30 '15 at 08:56
  • Because it logs its startup problems. note: errors at startup time. not errors at request time. you also get log entries when the startup succeeds. Like what your system logs when booting. – arkascha May 30 '15 at 08:57
  • @arkascha apache error log when I restarted it ... `[Sat May 30 14:29:44.672787 2015] [mpm_winnt:notice] [pid 5244:tid 536] AH00422: Parent: Received shutdown signal -- Shutting down the server. [Sat May 30 14:29:46.693901 2015] [mpm_winnt:notice] [pid 4772:tid 460] AH00364: Child: All worker threads have exited. [Sat May 30 14:29:46.892912 2015] [mpm_winnt:notice] [pid 5244:tid 536] AH00430: Parent: Child process 4772 exited successfully.` – Tabrez Ahmed May 30 '15 at 09:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/79182/discussion-between-tabrez-ahmed-and-arkascha). – Tabrez Ahmed May 30 '15 at 09:03

1 Answers1

2

There are a few things that you have not taken into account.

When you create Virtual Hosts Apache ignores the host defined in httpd.conf so you also need to create a Virtual Host for localhost. This explains why you cannot get to localhost when you have activated Virtual Hosts.

Apache is IPV4 and IPV6 aware, so when you create your domain names in the HOSTS file you need to do so for both the IPV4 and IPV6 stacks. So you would need to have a HOSTS file like this :-

#IPV4 Stack
127.0.0.1  localhost
127.0.0.1  project1

#IPV6 Stack
::1 localhost
::1 project1

The browser makes some arbitrary decision on whether to use the IPV4 stack or the IPV6 stack. Wish I understood why and for what reason it makes this decision better, but basically when you enter a domainname, the browser, or the networking stack, picks IPv4 or IPv6 for your first contact to a domain and then sticks to that decision, but it could use either.

Here is a post that should help you create Virtual Hosts

Community
  • 1
  • 1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149