如果您使用的是 Mac OS X 附带的内置 Apache,您将在 Apache 运行的默认用户和文件的所有权之间发生冲突。 Apache 可以访问它们,或者您可以读取和写入它们,但不能同时进行。
例如,如果我在 cding 到我的主目录之后在终端中发出 ls -al,我可以看到 ~/Sites 目录具有以下权限和所有权:
drwxr-xr-x+ 18 cppl staff 612 6 Apr 09:32 Sites
默认情况下,Apache 在_www 组中以_www 运行。
因此,您要么需要将您的用户添加到_www 组,要么以您的用户身份运行 Apache。
如果您将自己添加到_www 组,您仍然需要摆弄文件和目录权限。
如果您更改 httpd.conf 以便 Apache 以您的用户身份运行,您将需要找到并更改此部分:
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User _www
Group _www
具体来说,您需要将User 行设置为您的短用户名,例如对我来说是cppl,通常你会想要将组设置为staff,我猜是Mac OS X上用户的默认设置。例如
User cppl
Group staff
当然,如果您这样做,您可能应该通过防火墙限制对 Apache 的访问到 localhost 或您的专用网络(不包括路由器)。