沃梦达 / 编程问答 / php问题 / 正文

php 函数导致 FTP 中无人拥有 (99 99)?

Nobody owner (99 99) in FTP caused by php functions?(php 函数导致 FTP 中无人拥有 (99 99)?)

本文介绍了php 函数导致 FTP 中无人拥有 (99 99)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在服务器上创建文件和目录的脚本 (Joomla).问题是它在所有者 99 99(没人)下创建它们,并且在没有服务器管理员的帮助下我无法通过 FTP 删除或修改它们.

I have a script (Joomla) that creates files and directories on the server. The problem is that it creates them under owner 99 99 (nobody) and after I can't delete or modify them by FTP without the help of the server admin.

我认为这是php的move_uploaded_file函数.

I think that is move_uploaded_file function of php.

WHM 或服务器管理员是否有解决此问题的方法?我可以修改 ftp 中的默认所有者吗?

Is there any solution of this problem by the WHM or by the server admin? Can I modify the default owner in ftp?

推荐答案

发生的情况是 HTTP 服务器由名为nobody"的用户运行,而您的 FTP 用户是另一个用户.当上传发生时,HTTP 服务器以其用户名创建文件,而您的 FTP 用户没有写入(或删除)这些文件的权限.

What happens is the HTTP server is ran by a user called "nobody", and your FTP user is another one. When the upload occurs, the HTTP server creates the file under its username, and your FTP user has no permission to write (or delete) these files.

解决此问题的最简单方法(但并不真正安全)是将两个用户添加到同一组中,并更改文件权限以允许同一组的用户读取/写入这些文件.

The easiest way to fix this (but not really secure) is to add both users in a same group, and change the file permissions to allow users of the same group to read/write on these files.

您的管理员应该负责,但您必须调用 chmod() 来更改您上传文件的权限.

Your admin should take care of it, but you'll have to call chmod() to change the permissions of your uploaded files.

更好地解释:

linux/unix 文件权限由用户(u)、组(g)和其他人(o)的权限组成.我将在这里只介绍 3 种类型的文件权限,它们是读取 (r)、写入 (w) 和执行 (x).所以,你最终会得到这样的结果:

The linux/unix file permissions are composed by permissions of user (u), group (g) and others (o). I'll only cover 3 types of file permisions here, which are read (r), write (w) and execute (x). So, you end up having something like this:

-rw-rw---x   1 jweyrich  staff  12288 Oct 24 00:22 avatar.png

  • 第一个 rw- 是拥有文件的用户 (jweyrich) 的权限(读/写).
  • 第二个 rw- 是拥有文件(员工)的 GROUP 的权限(读/写).
  • 最后的 --x 是 OTHERS 用户的权限(执行)..
  • 您的 PHP 脚本以nobody"用户(并且由nobody"组)运行,因此您从 PHP 创建的每个文件都将由nobody"用户(及其组)所有.一个用户可以是一个或多个组的一部分.

    Your PHP scripts run as "nobody" user (and by, let's say, "nobody" group), so every file you create from your PHP will be owned by the "nobody" user (and his group). A user can be part of one or more groups.

    要解决权限问题,您的 FTP 用户和nobody"必须在公共组中,假设管理员将您的用户放在nobody"中.一旦他们在同一个组中,您的 PHP 脚本必须向nobody"组成员授予rw"(读/写)权限.这样做:

    To solve the permission problem, your FTP user and the "nobody" must be in a common group, let's say the admin put your user in the "nobody". Once they're in the same group, your PHP script has to give "rw" (read/write) permissions to the "nobody" group members. To do so:

    chmod("path_to_your_file", 0770);
    

    0770 相当于 "u+rwx,g+rwx,o-rwx" ,我在这里解释:

    The 0770 is equivalent to "u+rwx,g+rwx,o-rwx" , which I explain here:

    • u+rwx = 对于用户(所有者,即nobody"),赋予读/写/执行权限
    • u+rwx = 对于组(也是nobody"),赋予读/写/执行权限
    • o-rxw = 对于其他人,删除读/写/执行权限

    此后,您的 FTP 用户(现在属于nobody"组的一部分)将拥有对上传文件的读/写访问权限,因此也可以删除文件.它看起来像这样:

    After that, your FTP user, which is now part of the "nobody" group, will have read//write access to the uploaded files, and thus can also delete the files. It would look like this:

    -rwxrwx---   1 nobody  nobody  12288 Oct 24 00:22 avatar.png
    

    这不是对 unix 文件权限的理想介绍,但我希望这会有所帮助.

    It's not the ideal introduction to unix file permissions, but I hope this helps.

    这篇关于php 函数导致 FTP 中无人拥有 (99 99)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:php 函数导致 FTP 中无人拥有 (99 99)?

基础教程推荐