« | PHP and /tmp |
» |
I've just wasted a couple of hours banging my head against the wall trying to track down an obscure issue in an old PHP script. Essentially this script appended text to a file in /tmp
- it was to provide me with some debug.
I'd not used this script for a couple of years but needed to do some work on it today with debugging enabled so turned it on, ran the script via apache and ... no debug file appeared in /tmp
... which has odd.
So I wasted a lot of time looking at permissions, putting in debug, and generally doing all the usual tricks to track down the problem.
Eventually I discovered that it definitely was appending text to the file. I could tell that because echoing the output of file_get_contents()
of the file from within PHP showed the text was there and the file was getting bigger every time I ran the script.
But still no sign of it in /tmp
It clearly existed somewhere though so in the end I ran a 'find' run and, after about about fifteen minutes it found the file ... in:
/tmp/systemd-private-9a67486bf5794cd6aa91c6ce96f8da00-apache2.service-qur5aU/tmp/
Yup, systemd had decided, in its infinite wisdom, that apache should have its own /tmp directory. Joy.
The only good news is that it is possible to turn this off. On Ubuntu 16.04 (which is the release onto which we recently moved the server) you need to edit:
/etc/systemd/system/multi-user.target.wants/apache2.service
and replace PrivateTmp=true
with PrivateTmp=false
Once you've done that you need to not only restart apache but also run:
systemctl daemon-reload
(No, me neither).
Our live server is still on 14.04 so it's not affected by this yet, but it will be when we upgrade it which we're due to do later this year. Let's hope I remember to make this change there too.
Tags: linux, web design | Written 06/09/18 |
« | » |