views:

674

answers:

2

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?

A: 

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.

Pekka
i put permision 777 but it doesnt make change !! thx
hacen
@hacen then it could be that it's not possible to fix without the system administrator's help.
Pekka
A: 

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.

jweyrich
could you explaine more and what i have to do exactly
hacen
added a explanation on file permissions.
jweyrich