Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My envvar files has these lines in it:

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

My apache2.conf has these lines in it:

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

But when I run apache2 -M I get this:

apache2: bad user name ${APACHE_RUN_USER}

A temporary fix is to hard-code www-data into it my apache2.conf file. There was some speculation here that this was because some configuration script didn't replace the env vars correctly in my apache2.conf file. Regardless how do I get apache2 to consult my envvars file?

As another data point this site seems to indicate the envvars is generated at build, but read by apache2ctl at runtime, suggesting that this file isn't just poop leftover by the build process.

share|improve this question
add comment

2 Answers 2

From http://httpd.apache.org/docs/2.2/configuring.html:

The values of shell environment variables can be used in configuration file lines using the syntax ${ENVVAR}. If "ENVVAR" is the name of a valid environment variable, the value of that variable is substituted into that spot in the configuration file line, and processing continues as if that text were found directly in the configuration file. (If the ENVVAR variable is not found, the characters "${ENVVAR}" are left unchanged for use by later stages in the config file processing.)

So, the variable is indeed retrieved from the environment as expected. Now where does this happen?

In /etc/init.d/apache2, APACHE_ENVVARS is set to the path of the envvars file which is based on the initscript path. It usually results in APACHE_ENVVARS=/etc/apache2/envvars being set. Now, since this value equals to the default values as set in apache2ctl, it is not exported.

From /usr/sbin/apache2ctl:

# the path to the environment variable file
test -z "$APACHE_ENVVARS" && APACHE_ENVVARS="$APACHE_CONFDIR/envvars"
# pick up any necessary environment variables
if test -f $APACHE_ENVVARS; then
  . $APACHE_ENVVARS
fi

Explanation: if APACHE_ENVVARS is empty, use the default path which is /etc/apache2/envvars. If this file exists, "source" it (execute the commands from that file in the current environment).

Be sure that the envvars file does not contain any syntax errors. To perform such a check, use:

sh -n /etc/apache2/envvars && echo Syntax OK || echo FAIL

Errors are printed if any.

share|improve this answer
    
I performed the check and can verify that my envvars does not contain any syntax errors. I found a solution; see my answer below. –  Avery Chan Jun 6 '12 at 2:08
add comment
up vote 6 down vote accepted

After looking over the answer given by @Lekensteyn, I tried sudo apache2ctl -M with my apache2.conf reverted to the original. This worked so I dug into the man pages a bit. Here's what man apache2 had to say:

In  general, apache2 should not be invoked directly, but rather should 
be invoked via /etc/init.d/apache2 or apache2ctl. The default Debian 
configuration requires environment variables that are defined in 
/etc/apache2/envvars  and  are  not  available  if  apache2  is  
started  directly. However, apache2ctl can be used to pass arbitrary 
arguments to apache2.

So, the answer to this question is: You're not using apache2 correctly; use apache2ctl instead.

Thanks @Lekensteyn for pointing me in the right direction.

share|improve this answer
    
The even more correct way would be using the initscript: sudo stop apache2, sudo restart apache2 and sudo start apache2 (/etc/init.d/apache2 stop, etc.) –  Lekensteyn Jun 6 '12 at 7:49
    
In my case I was adding a umask setting to envvars, and even after restarting using apache2ctl restart it still didn't work, but restarting using service apache2 restart did work (service apache2 graceful did not). –  Matt Browne Jan 11 '13 at 18:22
    
it's recommended the use of service instead of apachectl, but if you need to use commands not linked to service command, like apachectl -S...this answer is great. upvote –  Feida Kila Aug 29 '13 at 8:58
    
FYI: Doing a /etc/init.d apache2 reload will not pickup the envvars additions, you have to stop and start the server –  ThaDon Mar 26 at 19:12
add comment

Your Answer

 
discard

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.