---
title: "apache2: bad user name ${APACHE_RUN_USER}"
author: "chen_gengjia"
date: "2010-12-29T21:32:52Z"
tags: ["Apache", "Linux", "PHP", "Ubuntu", "Windows"]
categories: ["编程语言"]
slug: "apache2-bad-user-name-apache-run-user"
draft: false
lastmod: "2010-12-29T21:32:52Z"
id: 855232
url: "https://chen-gengjia.iteye.com/blog/855232"
---

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}

 

解决方法：之前javaeye上有人的解决方法是直接改用户变量，apache2 启动会读取 /etc/apache2/apache2.conf 文件，里边用到了环境变量 APACHE\_RUN\_USER ;后者在 /etc/apache2/envars 里有定义 ，值为 www-data ，http://congfeng02.iteye.com/blog/435313 的方法是直接在 apache2.conf 的 user 那里用静态的值 www-data 。我在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 ..."

 

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

 

  -$ cd /etc/init.d/

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

 

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

或者

-$ cd /etc/init.d/

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