chown:不允许进行操作 [英] chown: Operation not permitted

查看:2201
本文介绍了chown:不允许进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我需要通过php脚本为系统中的其他用户设置文件所有者权限

I have problem where i need to set the file owner permission to different user in the system via a php script

所以我通过以下命令执行此操作,其中1002是系统的用户ID.

so i do this via this following command where 1002 is the user id of the system.

file_put_contents($filename, $content);
system("chown 1002 " . $filename . "");

但是我仅在生产服务器中遇到此错误(测试服务器运行正常)

however i get this error in productions server only (test server it works fine)

chown: changing ownership of `/var/spool/asterisk/06h12m7.call':
Operation not permitted

推荐答案

由于您将此问题标记为Linux,所以我假设您使用的是Apache服务器.在生产服务器中,拥有所有php进程的Apache进程通常由apache user或不是root user的其他用户执行.

Since you tagged this question as Linux I'm assuming that you use Apache server. In production servers the Apache process, which owns all php processes, are usually executed by the apache user or other user that is not the root user.

请记住,您正在尝试使用chown函数(将以apache用户身份执行)来更改您不拥有的文件的所有者. (是的,您只能将所有者更改为您拥有的文件).

Bearing that in mind, what you are trying to do is using the chown function, (which will be executed as apache user) to change the owner of a file that you don't own. (Yes, you can only change owners to the files you own).

您会引用php手册中的 chown 函数尝试更改所有者:

You see, quoting the php manual, the chown function attempts to change the owner:

尝试将文件文件名的所有者更改为用户user.只有超级用户可以更改文件的所有者.

Attempts to change the owner of the file filename to user user. Only the superuser may change the owner of a file.

在生产服务器中,通常以用户目录模式运行,这意味着您已绑定到主目录中的文件,如/home/yourusername/public_html之类,因此/var目录中的文件就被简单地删除了.范围之内(它们通常由root拥有),这就是为什么您不能穿衣服的原因.

In production servers usually you are running as in user directory mode, which means you are bound to the files that are in your home directory, something like /home/yourusername/public_html and as such, files inside the /var directory are simply out of your reach (They are usually owned by root) and that's why you can't chown.

我希望它能对您有所帮助.干杯!

I hope it helped. Cheers!

这篇关于chown:不允许进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆