[转] apache2: bad user name ${APACHE_RUN_USER}

apache2不能start/stop等操作, 报错: apache2: bad user name ${APACHE_RUN_USER}

解决方法如下:

一、

==============================================================================

Ubuntu - Apache2 - apache2: bad user name ${APACHE_RUN_USER}

在Ubuntu下sudo apt-get install apache2安装完Apache2以后,启动apache2的默认用户名是www-data, 属于www-data用户组

在shell中按如下输入

#apache2

会出现错误提示:

apache2: bad user name ${APACHE_RUN_USER}

解决办法:

1. 打开apache2的配置文件

#sudo gedit /etc/apache2/apache2.conf

(本来应该改envvars这个文件的,但是不知道为什么修改了不起作用)

2. 修改默认的用户名和组

找到 ${APACHE_RUN_USER} 和 ${APACHE_RUN_GROUP}

替换为自己的用户名和组,然后保存退出。

3.重启apache2

#apache2 -k graceful

注意,要让自己的用户对/var/www这个目录有写权限,否则你的脚本可能会出问题的。

当然,可以打开/etc/apache2/sites-enabled/000-default修改网站文件的根目录。

http://congfeng02.javaeye.com/blog/435313

==============================================================================

二、

==============================================================================

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

他的意思是命令行的目录问题,具体是

-$ cd /etc/init.d/

-$ sudo apache2 -k restart 会出现错误 ,这种情况下环境变量还没有读取

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

或者

-$ cd /etc/init.d/

-$ sudo ./apache2 -k restart 这两种命令都不会出现该错误

http://ubuntuforums.org/showthread.php?t=804436

==============================================================================

转载自: http://hi.baidu.com/qyf404/blog/item/3e8866c8f078c2027e3e6f32.html

参考文档: http://blog.163.com/qianxue126@126/blog/static/1627231382010326113256970/