PHP mkdir 和 apache 所有权

发布于 2024-08-27 05:35:06 字数 224 浏览 9 评论 0原文

有没有办法设置在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你列表最软的妹 2024-09-03 05:35:06

安全模式已在您的服务器上打开。函数 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 function mkdir() 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 use chmod() function in php.

不…忘初心 2024-09-03 05:35:06

另一种方法是将 apache 用户和“客户用户”放在一个新组中。另外,目录应该使用粘性位SGID,以便每个新文件都获得该新组的组分配。这样,网络服务器和“客户用户”就可以毫无问题地处理文件

[17:57] progman@proglap /tmp/test $ ls -al /tmp/test
total 9
drwxrwsr-x  2 root users   48 Apr  1 17:55 .
drwxrwxrwt 36 root root  9264 Apr  1 17:53 ..

正如您所看到的,该目录获得了粘位SGID,所有者是“用户”组,其中我(progman) 上午。否,如果另一个用户添加文件,组会自动设置为该组

[17:55] proglap ~ # touch /tmp/test/x

这是从 root 执行的。现在我们得到:

[17:57] progman@proglap /tmp/test $ ls -la /tmp/test
total 9
drwxrwsr-x  2 root users   72 Apr  1 17:59 .
drwxrwxrwt 36 root root  9264 Apr  1 17:53 ..
-rw-r--r--  1 root users    0 Apr  1 17:59 x

如您所见,添加的文件来自根目录,但组设置为users,这样可以删除它

[18:00] progman@proglap /tmp/test $ rm x
rm: remove write-protected regular empty file `x'? y
[18:01] progman@proglap /tmp/test $ ls -la /tmp/test
total 9
drwxrwsr-x  2 root users   48 Apr  1 18:01 .
drwxrwxrwt 36 root root  9264 Apr  1 17:53 ..

请记住,您仍然需要如果您想要编辑文件,请更改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 problems

[17:57] progman@proglap /tmp/test $ ls -al /tmp/test
total 9
drwxrwsr-x  2 root users   48 Apr  1 17:55 .
drwxrwxrwt 36 root root  9264 Apr  1 17:53 ..

As 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 group

[17:55] proglap ~ # touch /tmp/test/x

This is executed from root. Now we get:

[17:57] progman@proglap /tmp/test $ ls -la /tmp/test
total 9
drwxrwsr-x  2 root users   72 Apr  1 17:59 .
drwxrwxrwt 36 root root  9264 Apr  1 17:53 ..
-rw-r--r--  1 root users    0 Apr  1 17:59 x

As you see the added file is from root, but the group is set to users and this way I can remove it

[18:00] progman@proglap /tmp/test $ rm x
rm: remove write-protected regular empty file `x'? y
[18:01] progman@proglap /tmp/test $ ls -la /tmp/test
total 9
drwxrwsr-x  2 root users   48 Apr  1 18:01 .
drwxrwxrwt 36 root root  9264 Apr  1 17:53 ..

Keep in mind that you still need to change the chmod if you want to edit the file as rw-r--r-- is just group read access. But changing the chmod, maybe even working with umask, is better than dealing with root-access and using chown.

自控 2024-09-03 05:35:06

不直接,不。您不能将文件的所有权“放弃”给其他用户,除非您是 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

薄荷港 2024-09-03 05:35:06

查看 PHP chown() 函数

Check out PHP chown() function

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文