You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Desilets, Alain" <Al...@nrc-cnrc.gc.ca> on 2012/01/25 14:38:30 UTC

[users@httpd] RE: Can you use variables inside a conf file?

Nevermind, I found the answer on this page:

www.issociate.de/board/goto/1147159/Using_environment_variable_in_httpd.conf.html

Although it's an undocumented features, you can acess the OS env variables with a syntax like: ${WEBITEXT_HOME}.

I tried it and it works. The funny thing is that I am sure I tried this 3 weeks ago and it hadn't worked. Oh well.

Alain

-----Original Message-----
From: Desilets, Alain [mailto:Alain.Desilets@nrc-cnrc.gc.ca] 
Sent: Wednesday, January 25, 2012 6:51 AM
To: users@httpd.apache.org
Subject: [users@httpd] Can you use variables inside a conf file?

Hi, this is my first posting here.

I have a mod_perl application called WeBiText, which needs to push a number of directories on the Perl include path. At the moment, I do this by including the following in my httpd.conf file:

	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/WeBiText
	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/WeBiText/GUI
	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/WeBiText/bin
	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/IIPerlUtils/TestingAndDebugging
	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/IIPerlUtils
	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/PerlCorpusMiner

This is not great, because it hardcodes the pathes into the httpd.conf, which means that they possibly have to be changed everytime I install the app on a different machine.

I would much prefer to write something like this:

	PerlSwitches -I$ENV{WEBITEXT_HOME}/WeBiText
	PerlSwitches -I$ENV{WEBITEXT_HOME}/WeBiText/GUI
	PerlSwitches -I$ENV{WEBITEXT_HOME}/WeBiText/bin
	PerlSwitches -I$ENV{WEBITEXT_HOME}/IIPerlUtils/TestingAndDebugging
	PerlSwitches -I$ENV{WEBITEXT_HOME}/IIPerlUtils
	PerlSwitches -I$ENV{WEBITEXT_HOME}/PerlCorpusMiner

where WEBITEXT_HOME is an OS environment variable which already needs to be set for other reasons. Alternatively, I would be OK with using $WEBITEXT_HOME instead of $ENV{WEBITEXT_HOME}, where $WEBITEXT_HOME would be a variable whose value is passed to httpd using a command line option.

Is this possible? I looked around on the web and it seems that OS environment variables can only be accessed inside <Perl> sections. And unfortunately, I can't use <Perl> sections for that specific purpose, because those sections can only appear after you have loaded mod_perl, and by then it's already too late to modify the Perl include path.

Any help would be appreciated.

Thx.

Alain

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RE: Can you use variables inside a conf file?

Posted by Steve Swift <Sw...@swiftys.org.uk>.
I'll investigate mod_macro. Thank you.

On 29 January 2012 11:01, Rainer Jung <ra...@kippdata.de> wrote:

> On 29.01.2012 09:42, Steve Swift wrote:
>
>> Out of curiosity, is it possible to define the same environment
>> variable, but with different values, in different VirtualHosts? I
>> presume this can't be done, as all of the hosts would inherit the same
>> environment, including the environment variables.
>>
>> For example, I have live and test versions of every "server" in our
>> apache. The live server uses directory /cgi-bin/ and the test server
>> uses /cgi-test/. This means that we have to define things like aliases
>> in both live and test VirtualHosts. This means we can screw them up...
>>
>> I've always wanted to define some sort of "local" variable in each
>> VirtualHost, containing the location of the cgi directory. Then we could
>> INCLUDE the same set of aliases in both the live and test hosts, but
>> they would pick up their respective paths.
>>
>> In fact, I've often wished that the Apache configuration would support
>> its own internal variables, but so far nothing has happened. I must not
>> be wishing hard enough.
>>
>
> Sorry, mod_define and the builtin variables for Apache 2.4 only support
> global variables.
>
> Maybe mod_macro could help you. It allows to specify recurring config
> snipets which you can instantiate using parameters.
>
> Regards,
>
> Rainer
>
>  On 28 January 2012 14:53, Rainer Jung <rainer.jung@kippdata.de
>> <mailto:rainer.jung@kippdata.**de <ra...@kippdata.de>>> wrote:
>>
>>    On 25.01.2012 14:47, Desilets, Alain wrote:
>>
>>                    I use this syntax too, but I think it works for me
>>            only because of my
>>                    loading of a NON-STANDARD module, mod_define.
>>
>>            http://people.apache.org/~__**rjung/mod_define/mod_define.__**
>> html <http://people.apache.org/~__rjung/mod_define/mod_define.__html>
>>
>>            <http://people.apache.org/~**rjung/mod_define/mod_define.**
>> html <http://people.apache.org/~rjung/mod_define/mod_define.html>>
>>
>>
>>        It works for me and I don't have mod_define loaded.
>>
>>
>>    Using an environment variable with the ${MYVAR} syntax works without
>>    mod_define. If you want to define the value of the variable inside
>>    the httpd configuration files, you would need mod_define.
>>
>>    Major difference: environment variables can't be changed with
>>    "apachectl restart" or "apachectl graceful", because in both cases
>>    the httpd parent process keept running and all child processes are
>>    forked from it with an unchanged environment.
>>
>>    If you define the variables inside the configuration and use the
>>    additional module, any changes to the definitions will become active
>>    by "apachectl restart" and "apachectl graceful".
>>
>>    Starting with the forthcoming Apache 2.4 defining variable inside
>>    the httpd configuration will become a core feature.
>>
>>    Regards,
>>
>>    Rainer
>>
>
> ------------------------------**------------------------------**---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/**userslist.html<http://httpd.apache.org/userslist.html>>
> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
>  "   from the digest: users-digest-unsubscribe@**httpd.apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
Steve Swift
http://www.swiftys.org.uk

Re: [users@httpd] RE: Can you use variables inside a conf file?

Posted by Rainer Jung <ra...@kippdata.de>.
On 29.01.2012 09:42, Steve Swift wrote:
> Out of curiosity, is it possible to define the same environment
> variable, but with different values, in different VirtualHosts? I
> presume this can't be done, as all of the hosts would inherit the same
> environment, including the environment variables.
>
> For example, I have live and test versions of every "server" in our
> apache. The live server uses directory /cgi-bin/ and the test server
> uses /cgi-test/. This means that we have to define things like aliases
> in both live and test VirtualHosts. This means we can screw them up...
>
> I've always wanted to define some sort of "local" variable in each
> VirtualHost, containing the location of the cgi directory. Then we could
> INCLUDE the same set of aliases in both the live and test hosts, but
> they would pick up their respective paths.
>
> In fact, I've often wished that the Apache configuration would support
> its own internal variables, but so far nothing has happened. I must not
> be wishing hard enough.

Sorry, mod_define and the builtin variables for Apache 2.4 only support 
global variables.

Maybe mod_macro could help you. It allows to specify recurring config 
snipets which you can instantiate using parameters.

Regards,

Rainer

> On 28 January 2012 14:53, Rainer Jung <rainer.jung@kippdata.de
> <ma...@kippdata.de>> wrote:
>
>     On 25.01.2012 14:47, Desilets, Alain wrote:
>
>                     I use this syntax too, but I think it works for me
>             only because of my
>                     loading of a NON-STANDARD module, mod_define.
>
>             http://people.apache.org/~__rjung/mod_define/mod_define.__html
>             <http://people.apache.org/~rjung/mod_define/mod_define.html>
>
>
>         It works for me and I don't have mod_define loaded.
>
>
>     Using an environment variable with the ${MYVAR} syntax works without
>     mod_define. If you want to define the value of the variable inside
>     the httpd configuration files, you would need mod_define.
>
>     Major difference: environment variables can't be changed with
>     "apachectl restart" or "apachectl graceful", because in both cases
>     the httpd parent process keept running and all child processes are
>     forked from it with an unchanged environment.
>
>     If you define the variables inside the configuration and use the
>     additional module, any changes to the definitions will become active
>     by "apachectl restart" and "apachectl graceful".
>
>     Starting with the forthcoming Apache 2.4 defining variable inside
>     the httpd configuration will become a core feature.
>
>     Regards,
>
>     Rainer

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RE: Can you use variables inside a conf file?

Posted by Steve Swift <Sw...@swiftys.org.uk>.
Out of curiosity, is it possible to define the same environment variable,
but with different values, in different VirtualHosts? I presume this can't
be done, as all of the hosts would inherit the same environment, including
the environment variables.

For example, I have live and test versions of every "server" in our apache.
The live server uses directory /cgi-bin/ and the test server uses
/cgi-test/. This means that we have to define things like aliases in both
live and test VirtualHosts. This means we can screw them up...

I've always wanted to define some sort of "local" variable in each
VirtualHost, containing the location of the cgi directory. Then we could
INCLUDE the same set of aliases in both the live and test hosts, but they
would pick up their respective paths.

In fact, I've often wished that the Apache configuration would support its
own internal variables, but so far nothing has happened. I must not be
wishing hard enough.

On 28 January 2012 14:53, Rainer Jung <ra...@kippdata.de> wrote:

> On 25.01.2012 14:47, Desilets, Alain wrote:
>
>>        I use this syntax too, but I think it works for me only because of
>>> my
>>>        loading of a NON-STANDARD module, mod_define.
>>>
>>>                http://people.apache.org/~**rjung/mod_define/mod_define.*
>>> *html <http://people.apache.org/~rjung/mod_define/mod_define.html>
>>>
>>
>> It works for me and I don't have mod_define loaded.
>>
>
> Using an environment variable with the ${MYVAR} syntax works without
> mod_define. If you want to define the value of the variable inside the
> httpd configuration files, you would need mod_define.
>
> Major difference: environment variables can't be changed with "apachectl
> restart" or "apachectl graceful", because in both cases the httpd parent
> process keept running and all child processes are forked from it with an
> unchanged environment.
>
> If you define the variables inside the configuration and use the
> additional module, any changes to the definitions will become active by
> "apachectl restart" and "apachectl graceful".
>
> Starting with the forthcoming Apache 2.4 defining variable inside the
> httpd configuration will become a core feature.
>
> Regards,
>
> Rainer
>
>
> ------------------------------**------------------------------**---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/**userslist.html<http://httpd.apache.org/userslist.html>>
> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
>  "   from the digest: users-digest-unsubscribe@**httpd.apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
Steve Swift
http://www.swiftys.org.uk

Re: [users@httpd] RE: Can you use variables inside a conf file?

Posted by Rainer Jung <ra...@kippdata.de>.
On 25.01.2012 14:47, Desilets, Alain wrote:
>> 	I use this syntax too, but I think it works for me only because of my	
>> 	loading of a NON-STANDARD module, mod_define.
>>
>> 		http://people.apache.org/~rjung/mod_define/mod_define.html
>
> It works for me and I don't have mod_define loaded.

Using an environment variable with the ${MYVAR} syntax works without 
mod_define. If you want to define the value of the variable inside the 
httpd configuration files, you would need mod_define.

Major difference: environment variables can't be changed with "apachectl 
restart" or "apachectl graceful", because in both cases the httpd parent 
process keept running and all child processes are forked from it with an 
unchanged environment.

If you define the variables inside the configuration and use the 
additional module, any changes to the definitions will become active by 
"apachectl restart" and "apachectl graceful".

Starting with the forthcoming Apache 2.4 defining variable inside the 
httpd configuration will become a core feature.

Regards,

Rainer


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] RE: Can you use variables inside a conf file?

Posted by "Desilets, Alain" <Al...@nrc-cnrc.gc.ca>.
> 	I use this syntax too, but I think it works for me only because of my	
>	loading of a NON-STANDARD module, mod_define.
>
>		http://people.apache.org/~rjung/mod_define/mod_define.html

It works for me and I don't have mod_define loaded.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RE: Can you use variables inside a conf file?

Posted by "J.Lance Wilkinson" <jl...@psu.edu>.
Desilets, Alain wrote:
> Nevermind, I found the answer on this page:
> 
> www.issociate.de/board/goto/1147159/Using_environment_variable_in_httpd.conf.html
> 
> Although it's an undocumented features, you can acess the OS env variables with a syntax like: ${WEBITEXT_HOME}.
> 
> I tried it and it works. The funny thing is that I am sure I tried this 3 weeks ago and it hadn't worked. Oh well.
> 
> Alain

	I use this syntax too, but I think it works for me only because of my	
	loading of a NON-STANDARD module, mod_define.

		http://people.apache.org/~rjung/mod_define/mod_define.html

> 
> -----Original Message-----
> From: Desilets, Alain [mailto:Alain.Desilets@nrc-cnrc.gc.ca] 
> Sent: Wednesday, January 25, 2012 6:51 AM
> To: users@httpd.apache.org
> Subject: [users@httpd] Can you use variables inside a conf file?
> 
> Hi, this is my first posting here.
> 
> I have a mod_perl application called WeBiText, which needs to push a number of directories on the Perl include path. At the moment, I do this by including the following in my httpd.conf file:
> 
> 	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/WeBiText
> 	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/WeBiText/GUI
> 	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/WeBiText/bin
> 	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/IIPerlUtils/TestingAndDebugging
> 	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/IIPerlUtils
> 	PerlSwitches -IC:/Users/Desiletsa/Documents/eclipse_workspace/PerlCorpusMiner
> 
> This is not great, because it hardcodes the pathes into the httpd.conf, which means that they possibly have to be changed everytime I install the app on a different machine.
> 
> I would much prefer to write something like this:
> 
> 	PerlSwitches -I$ENV{WEBITEXT_HOME}/WeBiText
> 	PerlSwitches -I$ENV{WEBITEXT_HOME}/WeBiText/GUI
> 	PerlSwitches -I$ENV{WEBITEXT_HOME}/WeBiText/bin
> 	PerlSwitches -I$ENV{WEBITEXT_HOME}/IIPerlUtils/TestingAndDebugging
> 	PerlSwitches -I$ENV{WEBITEXT_HOME}/IIPerlUtils
> 	PerlSwitches -I$ENV{WEBITEXT_HOME}/PerlCorpusMiner
> 
> where WEBITEXT_HOME is an OS environment variable which already needs to be set for other reasons. Alternatively, I would be OK with using $WEBITEXT_HOME instead of $ENV{WEBITEXT_HOME}, where $WEBITEXT_HOME would be a variable whose value is passed to httpd using a command line option.
> 
> Is this possible? I looked around on the web and it seems that OS environment variables can only be accessed inside <Perl> sections. And unfortunately, I can't use <Perl> sections for that specific purpose, because those sections can only appear after you have loaded mod_perl, and by then it's already too late to modify the Perl include path.
> 
> Any help would be appreciated.
> 
> Thx.
> 
> Alain
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 


-- 
J.Lance Wilkinson ("Lance")		InterNet: Lance.Wilkinson@psu.edu
Systems Design Specialist - Lead	Phone: (814) 865-4870
Digital Library Technologies		FAX:   (814) 863-3560
E3 Paterno Library
Penn State University
University Park, PA 16802

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org