views:

37

answers:

1

I've got a web server running Ubutu 10.04 and Apache2 and PHP.

When I upload a file to the server through PHP, it creates it with 'rwxr-xr-x' and 'www-data www-data' as the user and group.

I've added my 'administrator' account to the 'www-data' group.

However, when I log in to my server through SSH and try and delete one of the files created, it says 'Permission Denied'? Even if I apply '0777' permission to it, I still can't delete the file.

The only way I've found that lets me delete the file is to CHOW the file to the 'administrator' account. Obviously I don't want to do this for every file uploaded, or indeed really CHMOD every file to '0777'.

What I am doing wrong here that won't let me create a file, then delete it using a different account?

+4  A: 

The ability to delete files is not controlled by the permissions on the file but by the permissions on the containing directory.

What are the permissions and owner/group of the parent directory? Those are the permissions you will need.

Looking at the permissions listed in your comment you will either need to add group write permissions for the group www-data (Although there are security considerations to take into account here) or add yourself to the sudoers file to allow your account to perform commands as the www-data user

EDIT

The permissions that the directory is created with will be affected by your current umask setting. You can change umask to allow the creation of files with arbitrary permissions as follows :-

$old = umask(0);
mkdir(date("Y", time()), 0775)
umask($old);
Steve Weet
drwxr-xr-x 2 www-data www-data 4096 2010-10-22 13:48 2010
Sjwdavies
Do a chmod 775 on the directory and you'll be all set. Stop and think of the security implications of this though. Who else is int he www-data group?
Paul Rubel
@ Paul Ruben: Only the 5 members of our IT Department (all developers). If I change my php to use the "mkdir(date("Y", time()), 0775)", it creates a directory like this "drwxr-xr-x 2 www-data www-data 4096 2010-10-22 14:09 2010"
Sjwdavies