79

I installed apache2 on ubuntu 13.10. If I try to restart it using

sudo /etc/init.d/apache2 restart

I get this message:

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

So I read that I should edit my httpd.conf file. But, since I can't find it in /etc/apache2/ folder, I tried to locate it using this command:

/usr/sbin/apache2 -V

But the output I get is this:

[Fri Nov 29 17:35:43.942472 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
[Fri Nov 29 17:35:43.942560 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Fri Nov 29 17:35:43.942602 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Fri Nov 29 17:35:43.942613 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Fri Nov 29 17:35:43.942627 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Fri Nov 29 17:35:43.947913 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Fri Nov 29 17:35:43.948051 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Fri Nov 29 17:35:43.948075 2013] [core:warn] [pid 14655] AH00111: Config variable ${APACHE_LOG_DIR} is not defined

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

Line 74 of /etc/apache2/apache2.conf is this:

Mutex file:${APACHE_LOCK_DIR} default

I gave a look at my /etc/apache2/envvar file, but I don't know what to do with it.

What should I do?

Kurt Bourbaki
  • 893
  • 1
  • 6
  • 7

8 Answers8

104

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"
Fritz
  • 126
  • 5
nadavkav
  • 1,469
  • 1
  • 11
  • 6
  • `/etc/apache2/envvars` doesn't exist – Mark Richman Jul 10 '14 at 18:20
  • 6
    The file does exist on my ubuntu system, but the shell doesn't recognize it as a shell script, so I need this: source /etc/apache2/envvars ; apache2 -V – Ben Crowell Jul 10 '14 at 18:59
  • 7
    Could just use `apachectl -V` instead of loading in the environment variables manually. – Sam Sehnert Jan 24 '17 at 22:58
  • If still not working, try `source /etc/apache2/envvars && sudo -E apache2 -V` or login as `root` and do per answer above. Sourcing the apache2 env to a regular user who then needs to use sudo will not work w/o "-E". Regular user perms cannot read certificate private folder among other problems. You will get an error. You need to sudo -E or run under root account completely. – B. Shea Aug 11 '17 at 14:36
  • This is very useful for running Apache as a docker foreground cmd. E.g. `CMD . /etc/apache2/envvars; /usr/sbin/apache2 -DFOREGROUND` – Alastair McCormack Sep 14 '17 at 10:49
  • hello, i'm getting this error: $ source /etc/apache2/envvars /etc/apache2/envvars (line 7): Missing end to balance this if statement if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then ^ from sourcing file /etc/apache2/envvars called on standard input source: Error while reading file '/etc/apache2/envvars' – Braian Mellor Oct 30 '17 at 12:34
  • 1
    This is the working solution. But I do not understand the "why". Has somebody further information? Thanks. – Toto Feb 16 '19 at 11:58
69
[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.

simhumileco
  • 155
  • 1
  • 8
ah83
  • 1,062
  • 9
  • 8
  • 1
    You're right about the init script. Then I added `ServerName localhost` to `apache2.conf` (because `httpd.conf` is not always used on Ubuntu) and now everything works as it should. Could you please add details to your answers, so that I can flag it as accepted? – Kurt Bourbaki Nov 30 '13 at 17:57
  • 1
    starting with `apache2ctl` didn't work for me, I had to **use the service**: `sudo service apache2 restart` – Édouard Lopez Aug 06 '14 at 13:29
  • 1
    But why did they break the `apache2` command in the first place? – reinierpost Jun 16 '16 at 19:24
  • 3
    This solutions only solves `AH00558: apache2: Could not reliably determine the server's fully qualified domain name` but it does not solve `Config variable ${APACHE_LOCK_DIR} is not defined`. – Vladimir Vukanac Jul 13 '16 at 20:36
  • for me also i see the same issue. – indianwebdevil Oct 14 '16 at 13:09
  • For completeness, a FQDN ends in a dot (`.`). It indicates the top of the DNS tree. So `localhost` is *not* FQDN, while `localhost.` is a FQDN. Similarly, `localhost.localdomain` is *not* a FQDN, while `localhost.localdomain.` is a FQDN. Also see W. Richard Stevens' [Unix and Networking bibles](http://www.kohala.com/start/). –  Jun 19 '17 at 22:53
  • This helped me big time. Thank you so much for the clear and concise explanation of the actual problem :) – Neeraj May 01 '18 at 14:13
  • There is no "ServerName" in /etc/apache2/apache2.conf – Black Jun 02 '22 at 08:03
7

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).

erny
  • 351
  • 1
  • 7
3

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

amd
  • 131
  • 2
2

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.

George
  • 121
  • 4
0

This works for me

sudo -u root bash -c "source /etc/apache2/envvars; apache2 -V"
Lihnjo
  • 25
  • 3
  • In the question, there was a problem (an error message about ServerName) and a failing debug method (which is caused by not sourcing the environment variables) .Your answer addresses the debug method, and not the question. – asdmin Jun 06 '16 at 09:28
-1

Maybe this will resolve your problem

sudo bash -c '. /etc/apache2/envvars ; apache2'
Eugen Konkov
  • 186
  • 1
  • 2
  • 13
  • 1
    read first, exactly this line was provided already, and it was also explained, why it is not a correct answer. – asdmin Jun 06 '16 at 11:08
-2

You need to update the DocumentRoot from /var/www/html to /var/www

Edit the file /etc/apache2/sites-available/000-default.conf as follows

DocumentRoot /var/www
Drew Khoury
  • 4,569
  • 8
  • 26
  • 28