Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.)

share|improve this question
What are you trying to accomplish with the system environment variables? – Shane Madden Jan 13 '13 at 20:29
@ShaneMadden, like I said in the second paragraph, I want to put the log files in a place pointed to by an env-var. – Synetech Jan 13 '13 at 20:42
What I want is to put the logs somewhere variable. That’s it. I am building a portable WAMP stack that can be run from a flash-drive. It is working great, but putting log files on flash-memory is bad because it will wear it out unnecessarily fast due to constant writes. I want to put the log files somewhere on the hard-drive and then when the server is shut down, zip them up and copy them to the flash-drive. I do not want to hard-code a path since the whole goal is to be able to run it from any system, hence the env-var (e.g., temp, userprofile, etc.) – Synetech Jan 13 '13 at 21:10
up vote 1 down vote accepted

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.

share|improve this answer
BINGO! It works beautifully (and you said it wasn’t possible ☺). It’s odd that it is hidden away like that. I tried finding it with Google but could not find it without getting too specific with stuff that would require already knowing the answer. – Synetech Jan 13 '13 at 22:31
@Synetech Yeah, I was thinking of the Define behavior in 2.4, which uses the same replacement syntax.. definitely not easy info to find. – Shane Madden Jan 13 '13 at 23:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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