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