Apache2 config variable is not defined

Solution 1:

Source your envvars by running it like this:

source /etc/apache2/envvars

and then

/usr/sbin/apache2 -V

You should get:

el@apollo:/home/el$ apache2 -V
Server version: Apache/2.4.7 (Ubuntu)
Server built:   Apr  3 2014 12:20:28
Server's Module Magic Number: 20120211:27
Server loaded:  APR 1.5.1-dev, APR-UTIL 1.5.3
Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

Solution 2:

[Fri Nov 29 17:35:43.942472 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined

This message is displayed because you directly executed the apache2 binary. In Ubuntu/Debian the apache config relies on the envvar file which is only activated.

If you start apache with the init script or apachectl.

Your original problem is that you have no a proper hostname (fqdn) for your machine.

If you can't change it, change the ServerName variable in /etc/apache2/apache2.conf to localhost or your prefered FQDN.


Solution 3:

Check your /etc/apache2/envvars for the APACHE_LOCK_DIR. In my Ubuntu 12.04, this is /var/lock/apache2$SUFFIX, being SUFFIX normally empty.

Check if the directory exists and is writable.

May it be that the envvars file is not sourced correctly? If you have a look at /etc/init.d/apache2 you can see that it sourced.

My (default) /etc/apache2/envvars:

# envvars - default environment variables for apache2ctl

# this won't be correct after changing uid
unset HOME

# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
    SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
    SUFFIX=
fi

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_PID_FILE=/var/run/apache2$SUFFIX.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale

export LANG

## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'

## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'

If nothing works I would try to reinstall the package(s).


Solution 4:

As other said, you have to load (source) your environment before running it directly Another option is to use: apache2ctl e.g.

sudo apache2ctl -S

to dump my hosts


Solution 5:

TL;DR; You should start apache2 using what you already have:

sudo /etc/init.d/apache2 {start|stop|restart}

Detailed:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

This message means you need to define your server name / domain name. It's not essential to do it for a localhost/testing of production, you don't need to worry about it.

When you try to run it the other way, using only apache2, you'll get those error messages because of what was said before: the environment variables are defined when you start using the default script in init.d.