Apache2 + PHP + private tmp directory

2018-01-22 at 10:50:03 | categories: tips, linux

Working on some web service I had an opportunity to work with PHP again.

Basically the service using some php script created files in /tmp which should be used by some node.js application for further processing/checking. The problem was it did not work on my debian strech instance in lxc container. To be precise the files kind of got created (return code was correct), but they were not in /tmp.

After some investigations it turned out that the "private tmp" security feature of systemd was a culprit.

Basically apache2.service got configured to use private tmp directory so any process started by apache2 (including php) was using /tmp/systemd....apache2.server.../tmp directory as its /tmp.

To check what is used I used this sudo systemctl cat apache2.service then to update just this one feature I used: sudo systemctl edit apache2.service and put there

[Service]
PrivateTmp=false

After restarting apache2 the php script was able to create files in /tmp directory as needed.