I am making use of PDFTK to watermark PDF files using the following command:
pdftk /tmp/55180af7c8c88.pdf stamp /tmp/stamp55180af7c95b84.58412952.pdf output /tmp/55180af7c95c81.06110501.pdf
However the above results in:
Error: Failed to open output file:
/tmp/55180af7c95c81.06110501.pdf
No output created.
Error: unable to open file for output: /tmp/55180af7c95c81.06110501.pdf
The above is a strange error because PDFTK should be creating that output file!
If I put sudo
infront of the command, no error is thrown. But I am writing to the tmp folder and this is writeable by all I thought?
I am running PDFTK from PHP's exec
command. To be 100% sure that this isn't a permissions issue, I made the /tmp
folder owner and group to be www-data
, which is the apache user but the same error is thrown.
I now have no idea what is going on, I appreciate any help!
You should not be fiddling around with the permissions for
/tmp
. It's an important part of the system. I suspect that the reason yourpdftk
command is failing is because/tmp
is incorrectly set up. To restore the permissions ontmp
run the following commands as root:The result will leave the permissions and owner/group of
/tmp
looking like this:Based on further investigation, I suspect that now we have got
/tmp
sorted out, the reason that thepdftk
is failing is that the output file already exists but is not writeable by the application. (Awaiting update via comments.)Have you got selinux enabled? Have a look at this previous question and answer, please.
I am editing this after your kind comment about SELinux/AppArmor not being relevant. If I were you, and this a long shot, I would take a look at the filesystem you are using for /tmp. If it is not tmpfs and it is get close to be full, you may experience issues similar to the one you describe. As you are probably aware of, once a filesystem gets close to be full, it only allows root to write on it.
Again, hope it helps!