PHP mkdir 和 apache 所有权
有没有办法设置在apache下运行的php来创建文件夹,该文件夹由创建它的程序所有者拥有,而不是由apache拥有?
使用 word press,它会创建要上传到的新文件夹,但这些文件夹归 apache.apache 所有,而不归其运行所在的站点所有。使用 ostickets 也会发生这种情况。现在我们必须通过 SSH 连接到服务器并 chmod 该文件夹,但似乎有一个设置可以覆盖任何执行此操作的程序之外的所有权。
Is there a way to set php running under apache to create folders with the folder owned by the owner of the program that creates it instead of being owned by apache?
Using word press it creates new folders to upload into but these are owned by apache.apache and not by the site that they are running in. This also happens using ostickets. For now we have to SSH into the server and chmod the folder, but it would seem there would be a setting somewhere to override the ownership outside of any program that does it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
安全模式
已在您的服务器上打开。函数mkdir()
创建文件夹,其所有者(“apache”、“none”、..)与当前脚本所有者不同。并且脚本无法将文件上传(移动、复制)到另一个所有者(与当前脚本所有者不同)的文件夹中。禁用
safe_mode
就可以了。请参阅 http://php.net/manual/en/features.safe-mode .php 了解详细信息。
PS 启用
safe_mode
后,您将无法在 php 中使用chmod()
函数。Safe_mode
is turn on on your server. The functionmkdir()
creates folder with owner ("apache", "none", ..) that different of the current script owner. And scripts couldn't upload (move, copy) files into that folder with another owner (that is not like current script owner).Disable
safe_mode
and that would be work.See http://php.net/manual/en/features.safe-mode.php for details.
P.S. With enable
safe_mode
you can't usechmod()
function in php.另一种方法是将 apache 用户和“客户用户”放在一个新组中。另外,目录应该使用粘性位
SGID
,以便每个新文件都获得该新组的组分配。这样,网络服务器和“客户用户”就可以毫无问题地处理文件正如您所看到的,该目录获得了粘位
SGID
,所有者是“用户”组,其中我(progman
) 上午。否,如果另一个用户添加文件,组会自动设置为该组这是从 root 执行的。现在我们得到:
如您所见,添加的文件来自根目录,但组设置为
users
,这样我可以删除它请记住,您仍然需要如果您想要编辑文件,请更改
chmod
,因为rw-r--r--
只是组读取访问权限嗯>。但是更改chmod
,甚至可能使用umask
,比处理 root 访问和使用chown
更好。Another way is to put the apache user and the "customer users" in a new group. Additional the directory should use the sticky bit
SGID
so each new file got the group assignment to this new group. This way the webserver and the "customer users" can work with the files without any problemsAs you see the directory got the stick bit
SGID
and the owner is the "users" group in which I (progman
) am. No if another user adds a file the group automatically get set to this groupThis is executed from root. Now we get:
As you see the added file is from root, but the group is set to
users
and this way I can remove itKeep in mind that you still need to change the
chmod
if you want to edit the file asrw-r--r--
is just group read access. But changing thechmod
, maybe even working withumask
, is better than dealing with root-access and usingchown
.不直接,不。您不能将文件的所有权“放弃”给其他用户,除非您是 root 用户。您可以使用“AssignUserID” apache指令来强制进行调查作为特定用户/组运行的特定虚拟主机。这样 Apache/PHP 将创建具有适当所有权的任何文件
Not directly, no. You can't "give away" ownership of a file to another user, unless you're root. You could investigate using the "AssignUserID" apache directive to force that particular vhost to run as a particular user/group. With that Apache/PHP would create any files with the appropriate ownership
查看 PHP chown() 函数
Check out PHP chown() function