apache2: bad user name ${APACHE_RUN_USER} 解决方法

之前一直用的nginx,换了份新工作,发现公司用的apache,安装了memcache扩展需要重启,Debian重启apache提示如下内容:
apache2: bad user name ${APACHE_RUN_USER}

apache启动时,读取/etc/apache2/apache2.conf文件,里边用到了环境变量 APACHE_RUN_USER,APACHE_RUN_USER定义在/etc/apache2/envvars
而不是使用默认的登录账户启动,因此apache提供了apache2ctl(Apache HTTP Server Control Interface)工具来使用。

  1. apache2ctl -k start

即可。

另外ubuntu的论坛里有另外一种解决方法以及发生该错误的原因说明:http://ubuntuforums.org/showthread.php?t=804436
下面是这位仁兄的解释:

I believe this is because etc/init.d is not in your command path. Unlike Windows, Linux does not look in the "current" directory for commands. So, if you are in /etc/init.d you can type "sudo ./apache2 restart" which will tell it to look in the current directory with the "./" The script in /etc/init.d/apache2 explicitly reads in the environment variables before calling /usr/sbin/apache2. /usr/sbin/ is in yoour command path, so that is the one that runs when you just type "apache2 ..."

他的意思是命令行的目录问题,在当前目录加./,不在当前目录写完整路径,另外加上sudo。例如:

  1. cd /etc/init.d/
  2. sudo apache2 -k restart

会出现错误 ,这种情况下环境变量还没有读取

改成:

  1. cd /etc/init.d/
  2. sudo ./apache2 -k restart

或者

  1. sudo /etc/init.d/apache2 -k restart

更多请支持:http://www.webyang.net/Html/web/article_172.html

相关推荐