3

How do I fix apache2 so that it starts with its environment variables?

My system is Linux Mint 17. I installed Apache2 with this command: sudo apt-get install php5 libapache2-mod-php5

Testing with a web browser worked correctly.

The problem is that this command says that there is an issue

/usr/sbin/apache2 -V
...
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf: Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

If I run these commands,

(from su -)
source /etc/apache2/envvars
service apache2 stop
service apache2 start
/usr/sbin/apache2 -V

the output looks OK (except for FQDN not determined). The problem is fixed.

When I reboot the system, apache starts up but does not have the envvars.

How do I fix this so that apache starts with its envvars?

Here is my /etc/init.d/apache2:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          apache2
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop apache2 web server
# Description:       Start the web server and associated helpers
#  This script will start apache2, and possibly all associated instances.
#  Moreover, it will set-up temporary directories and helper tools such as
#  htcacheclean when required by the configuration.
### END INIT INFO

DESC="web server"
NAME=apache2
DAEMON=/usr/sbin/$NAME

SCRIPTNAME="${0##*/}"
SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}"
if [ -n "$APACHE_CONFDIR" ] ; then
    if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
            DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}"
    else
            DIR_SUFFIX=
    fi
elif [ "${SCRIPTNAME##apache2-}" != "$SCRIPTNAME" ] ; then
    DIR_SUFFIX="-${SCRIPTNAME##apache2-}"
    APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX
else
    DIR_SUFFIX=
    APACHE_CONFDIR=/etc/apache2
fi
if [ -z "$APACHE_ENVVARS" ] ; then
    APACHE_ENVVARS=$APACHE_CONFDIR/envvars
fi
export APACHE_CONFDIR APACHE_ENVVARS

ENV="env -i LANG=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then
    ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR"
fi
if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then
    ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS"
fi


#edit /etc/default/apache2 to change this.
HTCACHECLEAN_RUN=auto
HTCACHECLEAN_MODE=daemon
HTCACHECLEAN_SIZE=300M
HTCACHECLEAN_DAEMON_INTERVAL=120
HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_cache_disk
HTCACHECLEAN_OPTIONS=""

# Read configuration variable file if it is present
if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then
    . /etc/default/apache2$DIR_SUFFIX
elif [ -f /etc/default/apache2 ] ; then
    . /etc/default/apache2
fi

PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)

VERBOSE=no
if [ -f /etc/default/rcS ]; then
    . /etc/default/rcS
fi
. /lib/lsb/init-functions


# Now, set defaults:
APACHE2CTL="$ENV apache2ctl"
HTCACHECLEAN="$ENV htcacheclean"
PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)
APACHE2_INIT_MESSAGE=""

CONFTEST_OUTFILE=
cleanup() {
    if [ -n "$CONFTEST_OUTFILE" ] ; then
        rm -f "$CONFTEST_OUTFILE"
    fi
}
trap cleanup 0  # "0" means "EXIT", but "EXIT" is not portable


apache_conftest() {
    [ -z "$CONFTEST_OUTFILE" ] || rm -f "$CONFTEST_OUTFILE"
    CONFTEST_OUTFILE=$(mktemp)
    if ! $APACHE2CTL configtest > "$CONFTEST_OUTFILE" 2>&1 ; then
        return 1
    else
        rm -f "$CONFTEST_OUTFILE"
        CONFTEST_OUTFILE=
        return 0
    fi
}
  • Could you paste the contents of /etc/init.d/apache2 file?. It looks APACHE_LOCK_DIR is not exported/declared in /etc/init.d/apach2. – Sree Nov 3 '14 at 13:40
  • @Sree I could not find APACHE_LOCK_DIR in my /etc/init.d/apache2 file. Should it be there? – Robert Tamlyn Nov 6 '14 at 2:05
  • I think it should be there since apache2 is looking for this variable. Try these things: 1) Add the line APACHE_LOCK_DIR=</path/to/dir> just below the line DAEMON=/usr/sbin/$NAME. You can get the value for /path/to/dir from /etc/apache2/envvars. 2)Try setting APACHE_LOCK_DIR globally as an environment variable and start apache2. You can copy the value of APACHE_LOCK_DIR from /etc/apache2/envvars file. – Sree Nov 6 '14 at 13:19
  • @Sree I added the line APACHE_LOCK_DIR=/var/lock/apache2 as you suggested. Now this line in apache2.conf fails: Mutex file:${APACHE_LOCK_DIR} default AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf: Invalid Mutex directory in argument file:${APACHE_LOCK_DIR} – Robert Tamlyn Nov 7 '14 at 2:04
1

I discovered the issue. To run the command /usr/sbin/apache2 -V it is necessary to source the apache environment variables first. I was misinterpreting the results. Doing this

source /etc/apache2/envvars; /usr/sbin/apache2 -V

works just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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