Mobile app version of vmapp.org
Login or Join
Gloria169

: SetEnv directive not working for localhost VirtualHost but works for other VirtualHost I have two virtual hosts declared: localhost and test. Both use the SetEnv directive and point to the same

@Gloria169

Posted in: #Apache2 #Virtualhost

I have two virtual hosts declared: localhost and test.

Both use the SetEnv directive and point to the same DocumentRoot:

NameVirtualHost *:80

<VirtualHost _default_:80>
DocumentRoot "/Users/mf/Sites/test"
SetEnv FROM_ROOT 'i like tacos' ## <- SetEnv
</VirtualHost>

<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Users/mf/Sites/test"
<Directory "/Users/mf/Sites/test">
Options Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SetEnv FROM_VHOST 'set in localhost vhost' ## <- SetEnv
</VirtualHost>

<VirtualHost *:80>
ServerName test
DocumentRoot "/Users/mf/Sites/test"
<Directory "/Users/mf/Sites/test">
Options Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SetEnv FROM_VHOST 'set in test vhost' ## <- SetEnv
</VirtualHost>


I have a test file /Users/mf/Sites/test/dump.php:

var_dump( $_SERVER );


For test/ everything works as I'd expect, $_SERVER['FROM_VHOST'] is available. dump.php outputs:

array (size=33)
'UNIQUE_ID' => string 'UY7bHMCoAXIAABkbAkMAAAAC' (length=24)
'FROM_VHOST' => string 'set in test vhost' (length=17)
'HTTP_HOST' => string 'test' (length=4)



For localhost/ things break down:

array (size=34)
'UNIQUE_ID' => string 'UY7bA8CoAXIAABkZAhQAAAAA' (length=24)
'FROM_ROOT' => string 'i like tacos' (length=5)
'HTTP_HOST' => string 'localhost' (length=9)



?


Why does localhost not have a FROM_VHOST environment variable?
Why does only localhost see the FROM_ROOT environment variable?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Gloria169

1 Comments

Sorted by latest first Latest Oldest Best

 

@Speyer207

Few things to try:

1) This could be because you have localbost setup as a hostname which would more and likely trigger the default, check in /etc/hostname or opt use a FQDN such as web.localhost

2) Another thing to try is putting Default at the bottom rather than top as those higher get more priority.

3) Obvious fix don't use localhost as a vhost :)

I'm not to confident with my answer but give a go (I'll revisit this when I get more time}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme