Apache Accessing System Environment Variables (for Log File Location)

apache-2.2environment-variableslog-files

Is there a way to let Apache access the system environment variables? I know it has its own environment and can pass them to spawned processes like PHP, but is there a way to let the server itself access the system’s variables?

In this specific case, what I want to do is to configure Apache to put log files in a folder pointed to by an environment variable (let’s use TEMP as an easy example). Unfortunately I cannot find anything helpful because it is a somewhat unusual task. Using the following won’t work:

CustomLog "%{TEMP}e/access.log" common

The man page says to use the OS to modify system variables, but it says nothing about accessing them.

Is there a way for Apache to access system variables? Is there a way to put log files in a variable location? (I am willing to update Apache if necessary.)

Best Answer

You can replace a system environment variable into the config:

CustomLog "${ENVVAR}/access.log" common

But, if that environment variable isn't set, the text is left alone (which will make for invalid syntax). See here.

A better option would probably be to include a file (Include /path/to/logging.conf) with the logging config, and change it as needed.

Related Topic