简体   繁体   English

即使所有者ID与用户ID相同,move_uploaded_file()也没有足够的权限

[英]move_uploaded_file() has insufficient permissions even though the owner id is the same as the user id

I have created a folder /home/UploadContent with owner:group as apache:apache, the same group and user as the php process. 我创建了一个文件夹/ home / UploadContent with owner:group as apache:apache,与php进程相同的组和用户。 I then used chmod to set the permissions to 775, which should allow php to write uploaded files to this directory. 然后我使用chmod将权限设置为775,这应该允许php将上传的文件写入此目录。 I tried it, and it gave me the same insufficient permissions error. 我试过了,它给了我相同的权限错误。

The exact error is "failed to open stream: Permission denied". 确切的错误是“无法打开流:权限被拒绝”。

I wrote a small php program to test whether or not: $Owner = fileowner("/home/UploadContent/"); $Current = exec("whoami"); $Id = exec("id -u " . $Current); echo ($Owner . " is owner, " . $Id . " is user."); 我写了一个小的php程序来测试是否: $Owner = fileowner("/home/UploadContent/"); $Current = exec("whoami"); $Id = exec("id -u " . $Current); echo ($Owner . " is owner, " . $Id . " is user."); $Owner = fileowner("/home/UploadContent/"); $Current = exec("whoami"); $Id = exec("id -u " . $Current); echo ($Owner . " is owner, " . $Id . " is user.");

This always returns "48 is owner, 48 is user." 这总是返回“48是所有者,48是用户”。

This would imply that php has the correct permissions to write,read, and execute, but it is still throwing errors. 这意味着php具有正确的写入,读取和执行权限,但它仍然会抛出错误。

[Promoted from a comment] [推荐评论]

Sounds like an SELinux problem... 听起来像SELinux问题......

Try running setenforce 0 at a bash prompt and then re-run the script. 尝试在bash提示符下运行setenforce 0 ,然后重新运行该脚本。 If this resolves the issue, you need to configure SELinux to allow your process access to the specified folder. 如果这样可以解决问题,则需要配置SELinux以允许您的进程访问指定的文件夹。

You can re-enable SELinux with setenforce 1 . 您可以使用setenforce 1重新启用SELinux。 Failing that, SELinux will be re-enabled at boot. 如果失败,SELinux将在启动时重新启用。

On Centos/RedHat, I use audit2allow to make appropriate policies by analysing the audit log. 在Centos / RedHat上,我使用audit2allow通过分析审计日志来制定适当的策略。 I have no idea what the standard is on other distros. 我不知道其他发行版的标准是什么。 This Wiki page explains what SELinux does and why it's important if you want your server to be secure. 这个Wiki页面解释了SELinux的作用以及为什么在您希望服务器安全的情况下这一点很重要。

I'm not aware of any way to configure SELinux via config files, however you can use chcon to change the security context of a specific resource (like a file). 我不知道有任何方法可以通过配置文件配置SELinux,但是您可以使用chcon来更改特定资源(如文件)的安全上下文。 More details of how security contexts work can be found here . 有关安全上下文如何工作的更多详细信息,请参见此处

Finally, you can disable SELinux entirely but this is not recommended. 最后,您可以完全禁用SELinux,但不建议这样做。

As pointed out by @VicSeedoubleyew in comments, there's a helpful checklist for resolving this and similar issues available here . 正如@VicSeedoubleyew在评论中指出的那样,有一个有用的清单可以解决此问题以及此处提供的类似问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM