Apache2 启动时缺少环境变量

Apache2 启动时缺少环境变量

如何修复 apache2 以便它以其环境变量启动?

我的系统是 Linux Mint 17。我使用以下命令安装了 Apache2: sudo apt-get install php5 libapache2-mod-php5

使用网络浏览器进行测试工作正常。

问题是这个命令说有问题

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

如果我运行这些命令,

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

输出看起来正常(除了未确定的 FQDN)。问题已解决。

当我重新启动系统时,apache 启动但没有环境变量。

我该如何解决这个问题,以便 apache 以其环境变量启动?

这是我的/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
}

答案1

我发现了这个问题。要运行命令 /usr/sbin/apache2 -V ,必须首先获取 apache 环境变量。我误解了结果。这样做

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

工作得很好。

相关内容