通过nginx访问时,php在/tmp/systemd-private-nABCDE/tmp中具有自己的/tmp [英] Php has its own /tmp in /tmp/systemd-private-nABCDE/tmp when accessed through nginx
问题描述
我发现有关php
和/tmp
文件夹的奇怪行为. Php与/tmp
一起使用时,将使用另一个文件夹. PHP 5.6.7,Nginx,PHP-FPM.
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.
我以两种方式执行相同的脚本:通过浏览器和通过Shell.但是,通过浏览器启动文件时,该文件不在实际的/tmp
文件夹中:
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)
文件在哪里?在/tmp
Where is the file? In /tmp
$ find / -name 185617.txt
/tmp/185617.txt
如果通过http://myserver.ru/script.php
访问它,我会得到
If access it via http://myserver.ru/script.php
I get
File /tmp/185212.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
但是文件在哪里?
$ find / -name 185212.txt
/tmp/systemd-private-nABCDE/tmp/185212.txt
为什么php认为/tmp
应该在/tmp/systemd-private-nABCDE/tmp
中?
Why does php thinks that /tmp
should be in /tmp/systemd-private-nABCDE/tmp
?
推荐答案
因为 systemd配置为为nginx提供私有/tmp .如果出于某些原因必须使用系统/tmp,则需要修改.service文件以读取"PrivateTmp = no".
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".
这篇关于通过nginx访问时,php在/tmp/systemd-private-nABCDE/tmp中具有自己的/tmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!