Apache2configurationvariables没有定义

我在Ubuntu 13.10上安装了apache2。 如果我尝试使用重新启动它

sudo /etc/init.d/apache2 restart 

我得到这个消息:

AH00558:apache2:无法可靠地确定服务器的完全限定的域名,使用127.0.1.1。 全局设置“ServerName”指令以禁止此消息

所以我读了我应该编辑我的httpd.conf文件。 但是,由于我在/etc/apache2/文件夹中找不到它,我试图用下面的命令find它:

 /usr/sbin/apache2 -V 

但是我得到的输出是这样的:

 [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} 

/etc/apache2/apache2.conf第74行是这样的:

 Mutex file:${APACHE_LOCK_DIR} default 

我看了看我的/etc/apache2/envvar文件,但是我不知道该怎么做。

我该怎么办?

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

显示此消息是因为您直接执行了apache2二进制文件。 在Ubuntu / Debian中,apacheconfiguration依赖envvar文件,只有使用init脚本或apachectl启动apache才会激活该文件。

你原来的问题是你的机器没有正确的主机名(fqdn)。 如果无法更改,请将/etc/apache2/apache2.confServerNamevariables更改为localhost或您的首选FQDN。

通过像这样运行你的envvars来源:

 source /etc/apache2/envvars 

接着

 /usr/sbin/apache2 -V 

你应该得到:

 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" 

检查你的/etc/apache2/envvars的APACHE_LOCK_DIR。 在我的Ubuntu 12.04中,这是/var/lock/apache2$SUFFIX ,通常/var/lock/apache2$SUFFIX为空。

检查目录是否存在并且是可写的。

可能是envvars文件没有正确的来源? 如果你看看/etc/init.d/apache2你可以看到它来源。

我的(默认) /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' 

如果没有任何工作,我会尝试重新安装软件包。

TL; DR; 你应该使用你已经有的开始apache2:

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

详细:

AH00558:apache2:无法可靠地确定服务器的完全限定的域名,使用127.0.1.1。 全局设置“ServerName”指令以禁止此消息

这个消息意味着你需要定义你的服务器名称/域名。 对本地主机/生产testing来说不是必须的,你不需要担心。

当你试图以另一种方式运行它时,只使用apache2 ,由于之前所说的,你会得到这些错误信息:当你在init.d开始使用默认脚本时,定义了环境variables。

正如其他人所说,你必须加载(来源)你的环境直接运行之前另一种select是使用: apache2ctl例如

sudo apache2ctl -S

转储我的主机

也许这会解决你的问题

 sudo bash -c '. /etc/apache2/envvars ; apache2' 

您需要将DocumentRoot从/var/www/html/var/www

编辑文件/etc/apache2/sites-available/000-default.conf ,如下所示

 DocumentRoot /var/www 

这对我有用

 sudo -u root bash -c "source /etc/apache2/envvars; apache2 -V"