Stack trying to migrate a configuration from Linux to Windows Apache 2.2 (via WAMP)
We are trying to set an ENV Apache variable to be used as DocumentRoot and rest of directives thereafter so we can use the same set of confs on server and local working copies of developers.
In Debian Linux Apache we have an envvars file that is loaded with "EXPORT" directives. This does not work on Windows but
Setenv ROOT_TO_FILES "C:/wamp/www/test"
Seems to work as displayed by a phpinfo()
But when we use it inside a DocumentRoot directive of an vhost:
DocumentRoot ${ROOT_TO_FILES}
Apache looks for that literal text under its own root.
This is the way we use it in Linux but we've also tried the syntax of env=ROOT_TO_FILES
The apache doc seems clear about how to "define" but not how to use. Also I see Apache 2.4 includes a new "Define" directive that seems to do exactly this which makes me think that it might not possible in previous versions.
Any samples of use under Windows Apache would be appreciated.
Apache's
SetEnv
directive just defines a variable that PHP or Perl scripts can use, for example they show up in PHP's$_SERVER[]
global array.SetEnv
, nor it's cousins, have have anything to do with use of variables in Apache directives.http://httpd.apache.org/docs/current/mod/mod_env.html#setenv
DocumentRoot
usually needs a literal string...What you want to do is use mod_macro (included in Apache 2.4.5 / *before that, you can find it as an extra module to download)... http://httpd.apache.org/docs/current/mod/mod_macro.html
*For Apache 2.2, search Google for mod_macro Apache 2.2 VC9. TS/Thread-safe is for mod_php, NTS/Non-Thread-Safe is for PHP-FCGI.
You can use Env variables even in windows apache, e.g. I use this code to set my servername:
But in this way you can only use env variables this way, if they are defined before starting your server, and the can NOT be changed by SetEnv.
If you like to use ${ROOT_TO_FILES} to like did in Linux you could
Here`s an example: (enter your path to httpd.exe if its different)
This was tested in apache 2.2 and 2.4.
If you like you can even use variables declared in apache.con with SetEnv e.g. like this:
But you need to know that variables set by SetEnv won`t be accessable for the "early" sections like access controll.
Take a look to the documentation http://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv if you need more informations about SetEnv (or SetEnvIf)