2

I'd like to include one or another external httpd.conf file in my main Apache httpd.conf based on an Environment Variable that is set externally.

So I would like to do something like:

if $(DEV_ENV) == "main"
Include "first file"
if $(DEV_ENV) == "alt"
Include "second file"

I've been looking at the mod_setenv module but that is for setting the environment variables within the Apache configuration. How can I use the environment variables and do comparisons on its values?

2 Answers 2

3

Sorry but you can't do this sort of dynamic logic on Includes. However certainly the Debian version allows direct reference to environment variables through a substitution pattern, e.g.

Include conf/${APACHE_RUNTIME_TYPE}/*.conf

Have a browse for "Apache2 envvars" to learn more.

1

Take a look at ifdefine. This evaluates options passed on the command line, rather than environment variables. The following matches your request:

<IfDefine main>
Include "first file"
</IfDefine>
<IfDefine alt>
Include "second file"
</IfDefine>
1
  • "evaluates options passed on the command line" - Starting in Apache 2.4 you can now Define "variables" in the Apache config (as well as variables defined on the command line with the -D flag).
    – MrWhite
    Nov 29, 2022 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.