I’m working on an upload script for students in my lab class to upload their assignments to a folder inside my home directory. The problem is that the script is run under the user apache and any directories and files created by the script end up owned by that user. In addition the permissions of the folder I wish the files to end up in have to be set wide open so that apache can create directories and move files into it (which of course will still be owned by apache).
I’m trying to replace an old script provided by the department which, among other problems, has about 5 different use cases where the student can receive a confirmation when the file wasn’t actually uploaded. That script does use chown apparently without any of the problems PHP has. Perhaps the python interpreter runs with different access setting that the PHP one does.
What tactics are there for handling this?
There’s a few ways to cope with this, but the most benign that I can imagine is to dedicated a sub-directory in your home directory for the purpose of uploading assignments.
All you have to do permissions wise is give the directory group ownership by some group the apache user belongs to. Suppose the webserver user is apache, and furthermore there is a group apache said user is a member of. You could also create a common group for this purpose that you and apache are part of.
Now let’s say the directory you want to put the uploaded files in is ~/homework-submissions
As yourself
With this arrangement in place newly created files will be owned by apache:apache, but the webserver should have no problem changing ownership at this point.