1

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

/var/ftp/client/dropbox/

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:

/var/ftp/client/dropbox/invoices/
/var/ftp/client/dropbox/invoices/bal_2013-06-01_2013-06-30.pdf
/var/ftp/client/dropbox/reports/
/var/ftp/client/dropbox/reports/visits/
/var/ftp/client/dropbox/reports/visits/bal_2013-06-01_2013-06-30.xlsx

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--

Meanwhile...

I have a php script located in say

/var/www/client/

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?

edit

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..

1 Answer 1

1

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.

1
  • 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, 2014 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .