Php has its own /tmp in /tmp/systemd-private-nABCDE/tmp when accessed through nginx
Solution 1
Because systemd is configured to give nginx a private /tmp. If you must use the system /tmp instead for some reason then you will need to modify the .service file to read "PrivateTmp=no".
Solution 2
If you are running multiple sites on the server then I think you'll want to leave PrivateTmp=yes so that each site remains segregated even in it's use of temp files. Could be a security issue otherwise, I'd imagine.
Related videos on Youtube
shukshin.ivan
I LIKE: complicated things, being close to a real business, not just business logic. GROWN UP WITH: physics, light athletics, self-made electronics (simple although) EDUCATED: MIPT, Moscow. Physics and math. Laser physics, biochips and ultrasound non-destructive control. LATEST INTERESTS: microcontrollers, IoT, effectiveness of a business, Laravel LOOKING FORWARD: move to North America and make a business much more successful
Updated on September 07, 2020Comments
-
shukshin.ivan over 3 years
I found strange behaviour concerning
php
and/tmp
folder. Php uses another folder when it works with/tmp
. Php 5.6.7, nginx, php-fpm.I execute the same script in two ways: via browser and via shell. But when it is launched via browser, file is not in real
/tmp
folder:<?php $name = date("His"); echo "File /tmp/$name.txt\n"; shell_exec('echo "123" > /tmp/'.$name.'.txt'); var_dump(file_exists('/tmp/'.$name.'.txt')); var_dump(shell_exec('cat /etc/*release | tail -n 1'));
php -f script.php
File /tmp/185617.txt bool(true) string(38) "CentOS Linux release 7.0.1406 (Core)
Where is the file? In /tmp
$ find / -name 185617.txt /tmp/185617.txt
If access it via
http://myserver.ru/script.php
I getFile /tmp/185212.txt bool(true) string(38) "CentOS Linux release 7.0.1406 (Core)
But where is the file?
$ find / -name 185212.txt /tmp/systemd-private-nABCDE/tmp/185212.txt
Why does php thinks that
/tmp
should be in/tmp/systemd-private-nABCDE/tmp
? -
shukshin.ivan almost 9 yearsYou are right, but that's
php-fpm
, notnginx
. I changed file/usr/lib/systemd/system/php-fpm.service
linePrivateTmp=true
intoPrivateTmp=false
. Now php uses correct/tmp
folder. -
Milan Maharjan about 8 yearswow this is brilliant. right what we were searching since 2 days :)
-
Gerben over 5 yearsDo consider the security implications of this change.
/tmp
may contain sensitive information and all php-scripts can suddenly access that information. -
Scott over 5 yearsWhat if your system does not have the system sub folder? might it be somewhere else?
-
domdambrogia almost 5 years@Scott
find / -type f -name 'php-fpm.service'
. You'll need to run that as sudo/root most likely but it will recursively located any file starting from the root (/) directory that is named php-fpm.service. -
stackprotector over 3 yearsThe XXX can be read from
/proc/sys/kernel/random/boot_id
but from where do you get YYY?