4

I have tried dozens of guides and read ton of information but I still can't find a fix for my problem. I have uninstalled, reinstalled and checked and double checked every possible issue.

The problem remains. No matter what change I make, document root ALWAYS show up as c:\wamp\www.

Even if I change the httpd.conf DocumentRoot to another path it still shows up as c:\wamp\www

What is strange is if the vhost was set up wrong, my index.php should not display. But in fact it does. And I have a line of code to echo the $_SERVER['DOCUMENT_ROOT'] and it ALWAYS shows as c:\wamp\www and not to ANY of the vhosts document roots I have assigned.

So the pages load, of course with errors. My pages ALL reference $_SERVER['DOCUMENT_ROOT'] and ALL work perfectly on my live sites.

So the bottom line is I have checked my configs backwards and forwards. / vs. \, hosts file is correct, document root paths are correct and point to actual folders that contain the correct files. I have played with every "standard" and non-standard possibility of config.

There must be some other element that's keeping this from working. Please help if you can.

Please don't suggest I try another config. I have tried them all.

Please tell me you know why this is happening and how to fix it. I have on script that almost did the trick but feel just short of the fix. I left a message for the poster and have not heard back from him.

I hope somebody here has a fix and not a suggestion to try yet another config. Unless you KNOW of the issue and have a fix, please don't reply. That might sound rude, but I have seen and tried all the configs.

NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
   DocumentRoot C:\wamp\www\itsaboutwirelessnetworks
   ServerName itsaboutwirelessnetworks.localhost
   ServerAlias itsaboutwirelessnetworks
</VirtualHost>

<VirtualHost 127.0.0.1:80>
   DocumentRoot C:\wamp\www\computerstore
   ServerName computerstore.localhost
   ServerAlias computerstore
</VirtualHost>

<VirtualHost 127.0.0.1:80>
  DocumentRoot C:\wamp\www
  ServerName localhost
   ServerAlias localhost
</VirtualHost>

Is the config. Why can't I edit with carriage returns in comments?

ScottyG
  • 51
  • 1
  • 6
  • Could you show us the relevant vhost configuration? Seems weird. – Wrikken Apr 05 '11 at 23:21
  • Argh. you do know you can edit your own question? A lot more readable markup there :) But that all seems OK indeed, I have no idea where to look. Anything else of interest in the `$_SERVER` array? – Wrikken Apr 05 '11 at 23:30
  • Where is the '$_SERVER' Array located? – ScottyG Apr 05 '11 at 23:35

2 Answers2

6

in C:\Windows\System32\drivers\etc\hosts add this line:

127.0.0.1 computerstore.local

in httpd.conf, make sure this line is uncommented:

Include "conf/extra/httpd-vhosts.conf"

(this should point to where your vhosts file is)

your httpd-vhosts.conf file should contain this:

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot              C:\wamp\www
    ServerName                127.0.0.1
    ServerAlias               localhost
    SetEnv APPLICATION_ENV    development
    SetEnv APPLICATION_DOMAIN localhost
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot              C:\wamp\www\conputerstore
    ServerName                computerstore.local
    ServerAlias               computerstore.local
    SetEnv APPLICATION_ENV    development
    SetEnv APPLICATION_DOMAIN computerstore.local
</VirtualHost>

If WAMP refuses to load up the vhosts file, move the vhosts config to the end of httpd.conf instead.

This should enable name-based configuration instead of IP-based. If you don't set it this way, Apache will resolve your sites' paths by IP, and since you specify a single IP, identical to all virtual hosts, the last one will take precedence over the previous ones. Your last vhost's docroot is C:\wamp\www - making the behaviour you describe absolutely normal.

UPDATE:

Since the document root C:\wamp\www\computerstore is specified for the domain name computerstore.local, remember to also go to http://computerstore.local in your browser. If you try http://localhost/computerstore, the domain name will be resolved as localhost, and in the first vhost, its document root is set to C:\wamp\www. computerstore will be treated just as a subdirectory; the docroot will not be changed in this case.

mingos
  • 23,778
  • 12
  • 70
  • 107
  • Made changes as you posted. No change in behavior. But you did tell me that the last vhost becomes the default, so that bit of info is new. What if I remove the vhost that refers to localhost? – ScottyG Apr 06 '11 at 00:11
  • For debug I have '' and it shows string 'C:/wamp/www' (length=11) so the change did not change the doc root. – ScottyG Apr 06 '11 at 00:20
  • So yet another configuration that does not change the doc root! Does anyone have a FIX for this? – ScottyG Apr 06 '11 at 00:29
  • @mingos, the change you posted did not work. Any other ideas? – ScottyG Apr 06 '11 at 00:45
  • I removed the localhost entries and the result was the page didn't load at all! Back to square one! @mingos can you offer any other ideas? – ScottyG Apr 06 '11 at 01:09
  • Sorry, this config is confirmed to be working on several computers. Would you mind uploading the `hosts`, `httpd.conf` and `httpd-vhosts.conf` files to some file sharing service so I can have a look? – mingos Apr 06 '11 at 16:06
  • @mingos You can grab them here! http://www.itsaboutniches.com/wampconfig.rar Let me know if I'm wrong, but so far they don't work for me. – ScottyG Apr 06 '11 at 21:17
  • Apart from needing a cleanup (repeated configurations), it seems fine. By the way, have you taken a look at your `hosts` file? There are over 14000 entries, with a comment "inserted by Spybot". You might want to consider using a good antivirus ;). Anyway, the only possibility that comes to my mind is a rewrite rule in your `.htaccess` files - is there one? – mingos Apr 06 '11 at 23:16
  • Oh, wait, after a second look, I think I've found it. You have DocumentRoot set to C:\wamp\www in httpd.conf. Comment this line out and restart the server, I think it should do the trick. – mingos Apr 06 '11 at 23:20
  • Man, I thought that would do the trick. But it didn't. It was a great suggestion. I had an Ah Ha moment after that and remmed out the – ScottyG Apr 07 '11 at 01:54
  • The 140000 entries are added by SB because there are 14000 known sites that dist. malware etc. The list gets added to all the time. And I use Symantec Corporate Ed. for AV. – ScottyG Apr 07 '11 at 02:26
  • I have also tried the port checker included with xampp and when apache is not running port 80 is not in use and when it is running it is used by apache. So I know I don't have a strange port issue. – ScottyG Apr 07 '11 at 16:01
  • And since this is on Vista, UAC is off, I run as Administrator, have full permissions on wamp and all files under it. – ScottyG Apr 07 '11 at 16:48
  • No idea then. With name-based virtual hosting, typing `http://computerstore.localhost` in the address bar has to take you to `C:\wamp\www\computerstore`, if your config contained an error, Apache wouldn't resolve the name correctly and thus wouldn't load your index.php file. I'm afraid I'm out of ideas. – mingos Apr 07 '11 at 17:39
  • Hm, one more thing: you ARE typing `http://computerstore.local` and not `http://localhost/computerstore`, right? Because in the latter case, `$_SERVER['DOCUMENT_ROOT']` *is* `C:\wamp\www`. – mingos Apr 07 '11 at 17:43
  • @mingos ! You are the man! I didn't try to use the domain by NOT using localhost as the domain prefix. I assumed, and it was a bad assumption, that in order to use and vhost, I needed to use the localhost prefix. In fact, just using the local domain computerstore or itsaboutwirelessnetworks does work. This should be in any FAQ for vhost use on wamp. And I can't understand why nobody else noticed or asked the question. – ScottyG Apr 08 '11 at 16:42
  • LOL, I assumed that since you defined a domain name, you intended to use it too :D. I'll update the answer to include the solution. – mingos Apr 08 '11 at 20:09
  • @Scotty G: if this answer resolves your issue, click the green arrow to accept the answer :) – Kyle Apr 11 '11 at 10:10
0

Did you try placing C:\wamp\www\conputerstore between quotes?

As an example here is my vhost config:

<VirtualHost *:8082>  
  DocumentRoot "c:/wamp/www/test"  
  DirectoryIndex index.php  
  <Directory "c:/wamp/www/test">  
    AllowOverride All  
    Allow from All  
  </Directory>  
</VirtualHost>
  • Yes, I tried the quotes and no quotes, changing / to \ and every combination of / \, with and without the declaration and quotes or not in that. Still no go. But from what I've read the " " quotes are for dirs that have spaces like "C:\wamp dir\www folder\" where c:\wamp\www does not require using quotes. Any other ideas? – ScottyG Apr 07 '11 at 15:35