没有人拥有者(99 99)在FTP中由php功能引起?
我有一个脚本(Joomla),可以在服务器上创建文件和目录。问题是它在所有者 99 99(无人)下创建它们,并且在没有服务器管理员帮助的情况下我无法通过 FTP 删除或修改它们。
我认为这是 php 的 move_uploaded_file
函数。
WHM 或服务器管理员是否有解决此问题的方法?我可以修改 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.
I think that is move_uploaded_file
function of php.
Is there any solution of this problem by the WHM or by the server admin? Can I modify the default owner in ftp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发生的情况是 HTTP 服务器由一个名为“nobody”的用户运行,而您的 FTP 用户是另一个用户。上传时,HTTP 服务器会在其用户名下创建文件,而您的 FTP 用户没有写入(或删除)这些文件的权限。
解决此问题的最简单方法(但并不真正安全)是将两个用户添加到同一组中,并更改文件权限以允许同一组的用户读取/写入这些文件。
您的管理员应该处理它,但您必须调用 chmod() 来更改上传文件的权限。
更好解释一下:
linux/unix 文件权限由用户(u)、组(g)和其他(o)的权限组成。
我在这里只介绍 3 种类型的文件权限,即读 (r)、写 (w) 和执行 (x)。因此,您最终会得到这样的结果:
您的 PHP 脚本以“nobody”用户(并且由“nobody”组)运行,因此您从 PHP 创建的每个文件都会由“nobody”用户(及其组)拥有。用户可以是一个或多个组的一部分。
要解决权限问题,您的 FTP 用户和“nobody”必须位于common组中,假设管理员将您的用户放入“nobody”中。
一旦他们位于同一组中,您的 PHP 脚本必须向“nobody”组成员授予“rw”(读/写)权限。为此:
0770 相当于 "u+rwx,g+rwx,o-rwx" ,我在这里解释:
之后,您的 FTP 用户,现在是“nobody”组将对上传的文件具有读//写访问权限,因此也可以删除文件。它看起来像这样:
这不是 unix 文件权限的理想介绍,但我希望这会有所帮助。
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.
Your admin should take care of it, but you'll have to call chmod() to change the permissions of your uploaded files.
Explaining it better:
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:
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.
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:
The 0770 is equivalent to "u+rwx,g+rwx,o-rwx" , which I explain here:
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:
It's not the ideal introduction to unix file permissions, but I hope this helps.
PHP 运行的用户 -
nobody
- 由系统管理员设置。你对此无能为力。如果您知道 FTP 用户 ID,可以尝试 chown() 更改文件的所有者。但通常情况下,您不会被允许在 PHP 中执行此操作。
根据服务器上的组情况,如果您在文件上传后使用 chmod 更改文件的访问权限,则 FTP 帐户可能可以访问该文件:
请先尝试此操作:
如果这不起作用,请尝试以下操作:
其中之一应该使 FTP 帐户可以使用该文件。
强烈建议不要使用
0666
,因为服务器上的其他用户可以写入您的文件,但在某些配置中,这是唯一的方法。The user that PHP runs under -
nobody
- is set by the system administrator. There's nothing you can do about that.You can try chown() to change the file's owner if you know the FTP user's ID. Usually though, you will not be allowed to do this from within PHP.
Depending on the group situation on the server, it could be that if you use
chmod
to change the file's access rights after the file has been uploaded, the FTP account can access the file:Try this first:
If that doesn't work, try this:
one of these should make the file usable by the FTP account.
The
0666
is highly discouraged because other users on the server could write into your files, but in some configurations, it's the only way to get going.