Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically, I am having an issue with a php script being able to move or delete files, and I know it has to do with permissions since that's what the php error from unlink() is telling me, but I'm not sure how to fix it. So I'm hoping if I explain the situation, someone might point me in the right direction, for I am a noob when it comes to linux CLI stuff...

Okay so I have an ftp dropbox location let's say it's located at


And I have created an ftp account with pure-ftpd. So when a file is uploaded to this directory, its owner is ftp-user and its group is ftp-group, which is what pure-ftpd runs as. This directory's user/group is set as ftp-user and ftp-group, respectively.

So, a 3rd party script is responsible for sending reports (files) to this dropbox location. The ftp account is supposed to have the ability to create subdirs within this directory, to categorize the files.

So for example, the file structure might look like this:


The "home" directory /var/ftp/client/dropbox/ chmod is drwxrwxr-x

When a subdir (e.g. invoices/) is created by ftp-user, it is getting chmod of drwxr-xr-x

When a file is uploaded (e.g. invoices/bal_2013-06-01_2013-06-30.pdf) by ftp-user, it is getting chmod of -rw-r--r--


I have a php script located in say


The script is supposed to open the files and do stuff like update database with category names (the subdir names) and file names etc.. and so far all that is fine. However....

So here's the problem...

Then the script is supposed to either move or delete the files (but not the subdirs) depending on reasons. But using File::delete() (Laravel 4) or just straight unlink() on the /path/to/file is returning a "permissions denied" error.

So, it looks like from using top that when my script is run, it (apache) is running under www-user and www-group. Makes sense that it'd be running as a different user/group. But what can I do to give permissions to apache/php to move/delete the files?

I have tried putting www-user in the the ftp-group group, but it's still giving me the "permissions denied" error. From research, I suspect maybe it has to do with a sticky-bit or something, but I'm not sure, and frankly, all this dir/file permission stuff is a little bit over my head at the moment..

Soo... any advice on what to do here?


One thought I had was, instead of having this script delete/move the files, I could insert the /path/to/files into a database, along with what action needs to be done. And then have a separate script that performs the action, and then put that script on a cronjob as root (or as ftp-user.. can I do that? I'm not sure..). I think this should work, but I'm not sure if it's a good idea to do that, and it seems like the better solution would be to sort out permissions..

share|improve this question
up vote 1 down vote accepted

You're on the right track by adding the www-user to the ftp-group. Unfortunately, the files you're creating don't have the group write permissions set. So only the owner (ftp-user) is able to write/delete them. You need to have those files created with write permissions for the group (ftp-group) as well. (This would be rw-rw-r-- instead of rw-r--r--)

The default permissions for new files are controlled via something called umask. Pure-FTP supports a umask directive within its configuration file. Essentially, you'll want to enter umask 113:003 into the configuration file, or -U 113:003 on the command line, to get the correct permissions.

share|improve this answer
aha, that did the trick! I added a file /etc/pure-ftpd/conf/Umask with 113 003 in it and restarted pure-ftpd and it works like a charm, thanks! – slinkhi Feb 21 '14 at 18:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.