macos 如何让 Apache 访问 MAC OSx 上的文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6079783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:04:39  来源:igfitidea点击:

How do I give Apache Access to folders on MAC OSx?

phpapachemacos

提问by Nick

I'm real new to Mac and Apache. I my development machine my website cannot access any files under the web roots /images or /css folders.

我是 Mac 和 Apache 的新手。我的开发机器我的网站无法访问 web 根目录 /images 或 /css 文件夹下的任何文件。

The apache log gives the following error:

apache 日志给出以下错误:

(13)Permission denied: file permissions deny server access:

(13)Permission denied:文件权限拒绝服务器访问:

The site is hosted up under the 'Sites' folder. I checked in 'Get Info' on this folder and it seems that 'Everyone' has read access. What gives?

该站点托管在“站点”文件夹下。我在此文件夹中签入了“获取信息”,似乎“所有人”都具有读取权限。是什么赋予了?

Thanks!

谢谢!

回答by pachopepe

The problem is that Apache runs with a user different to the user owner of files, and the Apache's user doesn't have read/write/execute permissions. In my case the user was _wwwand is member of the _wwwgroup.

问题是 Apache 与文件的用户所有者不同的用户运行,并且 Apache 的用户没有读/写/执行权限。在我的情况下,用户是_www并且现在是该_www组的成员。

I solved this issue changing the group of the files to the _www:

我解决了这个问题,将文件组更改为_www

  1. Look for the apache's user and group. I used this php script:

    <?php
    echo exec('whoami') . '<br>';
    echo exec('groups') . '<br>';
    ?>
    
  2. Login with the user owner of the files.

  3. Add the user owner of files to the _wwwgroup.

    $ sudo dseditgroup -o edit -a userOwnerOfFiles -t user _www
    
  4. Change the group of files needed to _www

    $ chgrp -R _www path/containing/files
    
  5. Change file permissions for the group

    $ chmod -R g+rwx path/containing/files
    
  1. 查找 apache 的用户和组。我使用了这个 php 脚本:

    <?php
    echo exec('whoami') . '<br>';
    echo exec('groups') . '<br>';
    ?>
    
  2. 使用文件的用户所有者登录。

  3. 将文件的用户所有者添加到_www组中。

    $ sudo dseditgroup -o edit -a userOwnerOfFiles -t user _www
    
  4. 更改所需的文件组 _www

    $ chgrp -R _www path/containing/files
    
  5. 更改组的文件权限

    $ chmod -R g+rwx path/containing/files
    

回答by Tony Adams

This was a tough one for me today. It turned out that I needed to give permissions to the web server to the entire directory tree all the way up to the doc root.

今天这对我来说很艰难。事实证明,我需要向 Web 服务器授予对整个目录树一直到文档根目录的权限。

It came up for me today because I'm using a virtual host and storing the files pretty far up a tree in my user directory.

它今天对我来说是因为我使用的是虚拟主机并将文件存储在我的用户目录中的树上。

I did not want to recursively change all the thousands of files in my Documents directory so I just chmod ed each folder in the path. In my home directory:

我不想递归地更改我的 Documents 目录中的所有数千个文件,所以我只是 chmod ed 路径中的每个文件夹。在我的主目录中:

$ chmod 755 Documents
$ chmod 755 Documents/projects
$ chmod 755 Documents/projects/dev
$ chmod 755 Documents/projects/dev/someglamorousclientname/
$ chmod 755 Documents/projects/dev/someglamorousclientname/docroot

回答by Nicolas

Another alternative way of solving this is using extended attributes in MacOSX

解决此问题的另一种替代方法是在 MacOSX 中使用扩展属性

chmod +a "_www allow list,read,search,readattr,readsecurity,file_inherit,directory_inherit" /path/to/document_root

chmod +a "_www 允许列表,读取,搜索,readattr,读取安全,file_inherit,directory_inherit" /path/to/document_root