Configure Apache user / group httpd.conf
I have an httpd.conf file containing the following:
<IfModule unixd_module> <If "env('OS') == 'Darwin'"> User daemon Group admin </If> <Else> User www Group scm </Else> </IfModule> What I'm trying to do is set the user ID for the httpd instance in my OSX development environment for one user, but another user when it is deployed to Ubuntu. I get a syntax error:
AH00526: Syntax error on line 32 of /usr/local/apps/apache2/conf/httpd.conf: User not allowed here I looked at the If directive and this is allowed here. If I comment on User / Group, I will not get a syntax error. Without IF / Else and using only one user, this works. If I try to use a condition with a user / group, I get an error message. Is this possible in httpd.conf? If so, how? Is there any other way to do the same? The environment variable "OS" is set in each environment with "export OS = uname ". This is in Apache httpd 2.4.4.
I finally found a moment to test it more deeply, and this is because the behavior of Override. I briefly checked source 2.4.4, and it seems to me that basically only directives that are in the Override list in the current contexts of a directory or location are overridden with If / Else.
Since the "User" and "Group" must be installed once for the entire installation and should not be changed using ".htaccess" or depending on the context of the Directory / Location, therefore they are not in some default "AllowOverride" list, and you cannot just put it in such a context as to make them redefinable. It makes sense to force User / Group parameters to be valid only on top of the apache's internal "configuration tree".
To achieve the behavior you need in a reasonable way, as I soon explained in my comment, you should use the "envvars" mechanism, available by default in Debian (possibly Ubuntu).
In short, the file / etc / apache 2 / envvars, containing for example
unset HOME if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}" else SUFFIX= fi export APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid export APACHE_RUN_DIR=/var/run/apache2$SUFFIX export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX export APACHE_LOG_DIR=/var/log/apache2$SUFFIX export LANG=C export LANG This is the source / inherited / etc / init.d / apache2 startup script, so the following section can be used in the main httpd configuration file (e.g. apache2.conf)
User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} A simple modification of / etc / apache 2 / envvars will allow you to get what you need. You can also change the default value for the user / group in the compilation settings for the user / group used on your OSX, and use only the script only on the Ubuntu side.