如何授予 Apache 访问 MAC OSx 上文件夹的权限?
我对 Mac 和 Apache 还很陌生。在我的开发机器上,我的网站无法访问 Web 根目录 /images 或 /css 文件夹下的任何文件。
apache 日志显示以下错误:
(13)权限被拒绝:文件权限拒绝服务器访问:
该站点托管在“站点”文件夹下。我检查了此文件夹的“获取信息”,似乎“每个人”都有读取权限。什么给?
谢谢!
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.
The apache log gives the following error:
(13)Permission denied: file permissions deny server access:
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
问题是 Apache 运行的用户与文件的用户所有者不同,并且 Apache 的用户没有读/写/执行权限。在我的例子中,用户是
_www
并且是_www
组的成员。我解决了这个问题,将文件组更改为
_www
:查找 apache 的用户和组。我使用了这个 php 脚本:
<前><代码>';
回显 exec('groups') 。 '
';
?>
使用文件的用户所有者登录。
将文件的用户所有者添加到
_www
组。更改
_www
所需的文件组更改该组的文件权限
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
_www
and is member of the_www
group.I solved this issue changing the group of the files to the
_www
:Look for the apache's user and group. I used this php script:
Login with the user owner of the files.
Add the user owner of files to the
_www
group.Change the group of files needed to
_www
Change file permissions for the group
解决此问题的另一种方法是在 MacOSX 中使用扩展属性
chmod +a "_www allowed list,read,search,readattr,readsecurity,file_inherit,directory_inherit" /path/to/document_root
Another alternative way of solving this is using extended attributes in MacOSX
chmod +a "_www allow list,read,search,readattr,readsecurity,file_inherit,directory_inherit" /path/to/document_root
我发现有两件事对我有用(我专门试图让 apache 能够访问“下载”文件夹):
在系统偏好设置 -> 中安全与隐私->隐私滚动到左侧的“完整磁盘访问”,确保在底部解锁,然后单击“+”添加应用程序。导航到 /usr/sbin 并找到可执行文件
httpd
并添加它,确保它启用了完全磁盘访问。重新锁定首选项右键单击 Finder 中的特定文件夹并选择“获取信息”,然后在“共享和”下选择“获取信息”。权限,允许“所有人”用户访问(或者如果您想提高安全意识,也许只允许“_www”用户 - 但我没有对此进行测试)。
这为我解决了这个问题
I've found 2 things did the trick for me (I was specifically trying to get apache to have access to the Downloads folder):
In System Preferences -> Security & Privacy -> Privacy scroll to Full Disk Access on the left, make sure you unlock at bottom, and then click the + to add an app. Navigate to /usr/sbin and find the executable
httpd
and add that, making sure it has full disk access enabled. Re-lock the preferencesRight click the particular folder in Finder and choose Get Info, then under Sharing & Permissions, allow access for the "everyone" user (or if you are trying to be more security conscious, perhaps only allow for "_www" user - but I did not test this).
That solved it for me
今天这对我来说是一件艰难的事。事实证明,我需要向 Web 服务器授予整个目录树的权限,一直到文档根目录。
今天我遇到了这个问题,因为我正在使用虚拟主机并将文件存储在我的用户目录中的树上。
我不想递归地更改文档目录中的所有数千个文件,因此我只是 chmod 路径中的每个文件夹。在我的主目录中:
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.
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:
此方法安全且安全。测试速度快,如果不工作也可以轻松切换回来(它不会把事情搞得更糟,这在解决此类问题时通常是一个问题:
httpd.conf< /code> (您可以在终端中使用
httpd -V
来完成)用户_www
群组_www
用户{您的用户名}
群组工作人员
也许您需要向您的
用户
和群组
添加其他内容:DocumentRoot
即可。复制此路径,然后使用cd
命令在终端中导航到该路径,例如:cd /Library/WebServer/Documents
httpd.conf
中调整您的User
和Group
与此相关ls -l
检查站点所有权,并更新相关的httpd.conf
。如果这不起作用,请不要忘记切换回:
用户_www
群组_www
This method is safe & fast to test, and easy to switch back if it's not working (it won't mess up things even more, which is ofter a problem when fixing these kind of issues:
httpd.conf
(you can do it withhttpd -V
in terminal)User _www
Group _www
User {your username}
Group staff
Maybe you will have to add something else to your
User
andGroup
:httpd.conf
file, you can also find a path to your webserver, just search forDocumentRoot
. Copy this path, and navigate to it in terminal withcd
command, for example:cd /Library/WebServer/Documents
ls -l
. This will give you info about webroot folder ownership. Adjust yourUser
andGroup
in thehttpd.conf
regarding thisls -l
, and updatehttpd.conf
regarding that.If this is not working, don't forget to switch back to:
User _www
Group _www