Here is the scenario:
I have a web application (php, mysql) which writes pdf files to a given directory: /var/www/myapp/tmp. I then use Gearman (worker php script run from terminal) to generate preview images from these pdf files. The worker script has access to the tmp directory at /etc/mount/tmp which is either symlinked to the /var/www/myapp/tmp directory (if the worker script runs on the same server as myapp) or mounted there using NFS (if the worker script runs on a different server).
The app creates subfolders in tmp with chmod 0777, in these subfolders the pdf files are placed. The worker grabs the file from the shared tmp directory (no problem there), generates a preview image, and should then write the preview image to the shared tmp directory.
The problem
I have this problem when I run everything locally (client, jobserver, worker), so with the symlinked tmp folder:
The subdirectory is not writable so I can't write the result and the worker fails.
Now the pdf files were written by the web app/gearman client and are owned by user _www. The worker script doesn't run through apache and is run under a different owner (me, logged in at the terminal), which gives me these permission problems I suppose.
I don't really understand why the folder isn't writable since I created it using 0777 permissions. Can the symlink have something to do with this?
In any case I don't know how to adequately fix this problem so both client and worker can work within the same folder without having permission problems. Can anyone help?
UPDATE
The first problem seemed to be the umask, if I set that to 0 the folders are writable, but this still forces me to set the permissions to 0777. How can I approach this more securely?