开发者

Nobody owner (99 99) in FTP caused by php functions?

开发者 https://www.devze.com 2022-12-26 12:06 出处:网络
I have a s开发者_如何学运维cript (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 F

I have a s开发者_如何学运维cript (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?


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:

-rw-rw---x   1 jweyrich  staff  12288 Oct 24 00:22 avatar.png
  • The first rw- is the permission (read/write) of the USER that owns the file (jweyrich).
  • The second rw- is the permission (read/write) of the GROUP that owns the file (staff).
  • The --x at the end are the permissions (execute) of the OTHERS users..

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:

chmod("path_to_your_file", 0770);

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

  • u+rwx = for user (owner, which is "nobody"), give read/write/execute permissions
  • u+rwx = for group (which is also "nobody"), give read/write/execute permissions
  • o-rxw = for others, remove the read/write/execute permissions

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

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


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:

chmod($uploaded_file, 0660); // owner+group read+write

If that doesn't work, try this:

chmod($uploaded_file, 0666); // global read+write

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号