Apache 环境变量问题

Apache envvars issue

我正在尝试从 Debian 7 上的 Apache 2.2 迁移到 CentOS 7 上的 Apache 2.4。 据我所知,在 Debian 7 上有一个名为 "envvars" 的文件,如下所示,它必须存在于 CentOS 7 上。

# 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

我在 httpd.conf 所在的 conf 下创建了相同的文件,但它没有工作,并将内容添加到 /etc/sysconfig/httpd,但错误停止了 运行 apache 服务器,如下所示。

Jun 17 17:48:35 ww-test httpd[5707]: [Wed Jun 17 17:48:35.473658 2020] [core:warn] [pid 5707] AH00111: Config variable ${APACHE_PID_FILE} is not defined
Jun 17 17:48:35 ww-test httpd[5707]: [Wed Jun 17 17:48:35.473857 2020] [core:warn] [pid 5707] AH00111: Config variable ${APACHE_RUN_USER} is not defined
Jun 17 17:48:35 ww-test httpd[5707]: [Wed Jun 17 17:48:35.473864 2020] [core:warn] [pid 5707] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
Jun 17 17:48:35 ww-test httpd[5707]: [Wed Jun 17 17:48:35.473885 2020] [core:warn] [pid 5707] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
Jun 17 17:48:35 ww-test httpd[5707]: [Wed Jun 17 17:48:35.495541 2020] [core:warn] [pid 5707] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
Jun 17 17:48:35 ww-test httpd[5707]: AH00543: httpd: bad user name ${APACHE_RUN_USER}
Jun 17 17:48:35 ww-test systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jun 17 17:48:35 ww-test systemd[1]: Ignoring invalid environment assignment 'export APACHE_RUN_USER=apache': /etc/sysconfig/httpd
Jun 17 17:48:35 ww-test systemd[1]: Ignoring invalid environment assignment 'export APACHE_RUN_GROUP=apache': /etc/sysconfig/httpd
Jun 17 17:48:35 ww-test systemd[1]: Ignoring invalid environment assignment 'export APACHE_PID_FILE=/var/run/httpd$SUFFIX.pid': /etc/sysconfig/httpd
Jun 17 17:48:35 ww-test systemd[1]: Ignoring invalid environment assignment 'export APACHE_RUN_DIR=/var/run/httpd$SUFFIX': /etc/sysconfig/httpd
Jun 17 17:48:35 ww-test systemd[1]: Ignoring invalid environment assignment 'export APACHE_LOCK_DIR=/var/lock/httpd$SUFFIX': /etc/sysconfig/httpd
Jun 17 17:48:35 ww-test systemd[1]: Ignoring invalid environment assignment 'export APACHE_LOG_DIR=/var/log/httpd$SUFFIX': /etc/sysconfig/httpd
Jun 17 17:48:35 ww-test kill[5708]: kill: cannot find process ""
Jun 17 17:48:35 ww-test systemd[1]: httpd.service: control process exited, code=exited status=1
Jun 17 17:48:35 ww-test systemd[1]: Failed to start The Apache HTTP Server.

我尝试了 source envvars 来测试 environemts 是否有效,但它没有。 有什么方法可以添加环境变量,以便它在我启动 Apache 时应用?

谢谢!

httpd.conf 中声明您的变量:定义(最好在第一行)

Define APACHE_RUN_USER Apache

您以后可以像这样使用这个变量:

User ${APACHE_RUN_USER}

参考link了解更多信息。