PHP chmod( ): 不允许操作,是否涉及安全模式弃用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23070266/
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-08-25 16:27:54  来源:igfitidea点击:

PHP chmod( ):Operation not permitted, safe_mode deprecation involved?

phpapachefile-permissionschmod

提问by Joel Hernandez

I'm struggling a bit to grasp the concept of chmod()from PHP as the course I'm currently taking is a bit outdated and involves safe_mode. It states that as safe_mode is turned off, the restrictions to modify permissions with chmod()to a file when the owner is not the same as the one executing the command are removed. I'm working with PHP 5.5.9 in conjuncture with XAMPP, I've verified that the flags are turned off (just in case), but can't seem to get it working. As I execute the following PHP script:

我正在努力掌握chmod()PHP的概念,因为我目前正在学习的课程有点过时并且涉及安全模式。它指出,当关闭 safe_mode 时,chmod()当所有者与执行命令的人不同时,修改文件权限的限制将被删除。我正在与 XAMPP 一起使用 PHP 5.5.9,我已经验证标志已关闭(以防万一),但似乎无法使其正常工作。当我执行以下 PHP 脚本时:

echo "File permissions :" .  decoct(fileperms("file_permissions.php"));
chmod("file_permissions.php" ,0777);

I receive the following output :

我收到以下输出:

Warning: chmod(): Operation not permitted

My permissions for the file are the following

我对文件的权限如下

-rwxrwxrwx@  1 joelhernandez  staff     24 Apr 14 06:59 file_permissions.php

And I've executed ps aux | grep httpdto confirm that the my webserver is operating under the user "daemon" .

我已经执行ps aux | grep httpd以确认我的网络服务器在用户 "daemon" 下运行。

As I change the file ownership to daemon:

当我将文件所有权更改为daemon 时

-rwxrwxrwx@  1 daemon  staff     24 Apr 14 06:59 file_permissions.php

Everything works, I do not understand why as I had understood that with safe_mode turned off, file ownership would mean nothing, instead file permissions were the way to handle access.

一切正常,我不明白为什么正如我所理解的那样,在关闭 safe_mode 的情况下,文件所有权将毫无意义,相反,文件权限是处理访问的方式。

回答by nobody

The daemonuser is not root, so it is not allowed to change the mode of a file owned by a different user. PHP safe_mode is not the cause here. The warning is telling you that the attempted operation failed because the web server user did not have permission to make the mode change.

daemon用户是不是root,所以它不允许更改由其他用户拥有的文件的模式。PHP safe_mode 不是这里的原因。该警告告诉您尝试的操作失败,因为 Web 服务器用户没有进行模式更改的权限。

The operation succeeded after you manually changed the ownership of the file to daemonbecause users are allowed to change the mode of files they own.

手动更改文件的所有权后操作成功,daemon因为允许用户更改他们拥有的文件的模式。