Score:0

If statement using an environment variable

jp flag

In my apache configuration, I am trying to only activate a snippet of code if an environment variable is set to true.

So I have something like this:

<If "'${MY_ENV_VAR}' == 'true'">
  # do something
</If>

For some reason, this is not currently working, does anybody have any idea what might be wrong here?

Many thanks

vidarlo avatar
ar flag
Where is the variable set? Using `SetEnv`, or in the calling shell? If so, do you use PassEnv?
jp flag
It is set in the shell
vidarlo avatar
ar flag
Do you [use the passenv directive](https://httpd.apache.org/docs/2.4/mod/mod_env.html)? Please post more of your configuration.
jp flag
no there is not much more in my config, I have this environment variable in the shell, so that if I type "env" in the shell, I see MY_ENV_VAR=true. I'd like to use this var to enable or disable a section in apache but can't find exactly how. (thanks for your time)
Score:2
ar flag

It's probably not working because you're not telling apache to pass the environment variables using the PassEnv directive.

You need mod_env loaded, and you have to include a stanza such as

PassEnv MY_ENV_VAR

It's fairly well documented in the Apache Manual

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.