I’m trying to get my head around directory and file permissions and would like some advice.
I want to create a script that lets users upload files and the script will then store those files in a directory. Another script should be able to delete those files when they’re no longer needed.
In the past I’ve been able to do this just fine but only if I set the permissions on the directory that holds the files to 777. Of course 777 gives everyone full access so I’d much rather restrict the permissions to something like 755.
If I FTP into my website and create a directory then the owner is set to “aweb4u” (my FTP login name) and the group is also set to “aweb4u”. I understand that my scripts are run as the Apache user and so they don’t have write access to any directory I create through FTP, unless I change the permissions to 777.
I’ve tried experimenting by running a script that creates a directory and then seeing who the owner/group is and what the permissions are. Doing this I see that the owner is “cwww” and the group is also set to “cwww” (I assume that cwww is the Apache user). The permissions were set to 755.
This is will allow my scripts to write to the directory, and offers the protection I’d like. But there’s one downside to this and that is that I no longer have write permissions to the directory myself if I FTP into the site. It would definitely be handy for me to have write permissions too, so I can manually delete any files that I want to or upload any files that I want to.
Any suggestions on how I can do this?