授予 php 创建文件的权限,但没有权限错误
Give php permission to create files without permissions error
在 PHP 中使用 move_uploaded_file()
函数时出现错误:
Warning: move_uploaded_file(...): failed to open stream: Permission denied in ...
在我的服务器上,我拥有 public_html
权限,例如:
drwxr-sr-x 7 user www-data 4096 Apr 27 17:48 public_html
递归遍历整个目录。
您知道为什么这可能不起作用吗?或者我可以做些什么来帮助我找出为什么这不起作用。
系统
服务器实际上是一个集群,文件在NAS上,php在集群上。我正在 NAS 设备上执行所有权限命令,因为这是用户 FTP 的位置。
首先,SUID 和 SGID 仅在与可执行文件一起使用时才有意义。
来自 http://www.codecoffee.com/tipsforlinux/articles/028.html :
SUID (Set User ID) Bit
[...] in case I have an application whose owner is ' root ' and it has its SUID bit set, then when I run this application as a normal user, that application would still run as root. Since the SUID bit tells Linux that the the User ID root is set for this application and whenever this application executes it must execute as if root was executing it (since root owns this file)
SGID (Set Group ID) bit
Just like SUID, setting the SGID bit for a file sets your group ID to the file's group while the file is executing. IT is really useful in case you have a real multi-user setup where users access each others files. As a single homeuser I haven't really found a lot of use for SGID. But the basic concept is the same as the SUID, the files whose SGID bit are set would be used as if they belong to that group rather than to that user alone.
因此,如果您的 none 个 Web 文件需要作为正常进程执行,最好保留 SGID。
最后,如果您没有更改 Web 服务器的安全上下文,它(很可能,因为您没有提到任何路径)会尝试移动位于在目录 www-data
中只能 读取 。要移动文件,您需要对文件 和 将 移动到的目录具有写入权限。所以 www-data
应该被授予 写入 访问权限
- 文件首先到达的目录(默认情况下:
/tmp
,在这种情况下无需执行任何操作)
- 要移动到的目标目录。
用户 www-data 无法写入 public_html 目录。在您的 public_html 上使用 chmod 以授予 www-data 写入权限:
chmod 775 public_html -R
在 PHP 中使用 move_uploaded_file()
函数时出现错误:
Warning: move_uploaded_file(...): failed to open stream: Permission denied in ...
在我的服务器上,我拥有 public_html
权限,例如:
drwxr-sr-x 7 user www-data 4096 Apr 27 17:48 public_html
递归遍历整个目录。
您知道为什么这可能不起作用吗?或者我可以做些什么来帮助我找出为什么这不起作用。
系统
服务器实际上是一个集群,文件在NAS上,php在集群上。我正在 NAS 设备上执行所有权限命令,因为这是用户 FTP 的位置。
首先,SUID 和 SGID 仅在与可执行文件一起使用时才有意义。
来自 http://www.codecoffee.com/tipsforlinux/articles/028.html :
SUID (Set User ID) Bit
[...] in case I have an application whose owner is ' root ' and it has its SUID bit set, then when I run this application as a normal user, that application would still run as root. Since the SUID bit tells Linux that the the User ID root is set for this application and whenever this application executes it must execute as if root was executing it (since root owns this file)
SGID (Set Group ID) bit
Just like SUID, setting the SGID bit for a file sets your group ID to the file's group while the file is executing. IT is really useful in case you have a real multi-user setup where users access each others files. As a single homeuser I haven't really found a lot of use for SGID. But the basic concept is the same as the SUID, the files whose SGID bit are set would be used as if they belong to that group rather than to that user alone.
因此,如果您的 none 个 Web 文件需要作为正常进程执行,最好保留 SGID。
最后,如果您没有更改 Web 服务器的安全上下文,它(很可能,因为您没有提到任何路径)会尝试移动位于在目录 www-data
中只能 读取 。要移动文件,您需要对文件 和 将 移动到的目录具有写入权限。所以 www-data
应该被授予 写入 访问权限
- 文件首先到达的目录(默认情况下:
/tmp
,在这种情况下无需执行任何操作) - 要移动到的目标目录。
用户 www-data 无法写入 public_html 目录。在您的 public_html 上使用 chmod 以授予 www-data 写入权限:
chmod 775 public_html -R