php通过nginx访问时在/tmp/systemd-private-nABCDE/tmp中有自己的/tmp

标签 php nginx centos7 tmp

我发现有关 php/tmp 文件夹的奇怪行为。 Php 在使用 /tmp 时使用另一个文件夹。 PHP 5.6.7,nginx,php-fpm。

我以两种方式执行相同的脚本:通过浏览器和通过 shell。但是当它通过浏览器启动时,文件不在真正的 /tmp 文件夹中:

<?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

$ find / -name 185617.txt
/tmp/185617.txt

如果通过 http://myserver.ru/script.php 访问它,我得到

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 中?

最佳答案

因为 systemd is configured to give nginx a private /tmp .如果出于某种原因您必须改用系统/tmp,那么您将需要修改 .service 文件以读取“PrivateTmp=no”。

关于php通过nginx访问时在/tmp/systemd-private-nABCDE/tmp中有自己的/tmp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30444914/

相关文章:

apache - CentOS 7 + PHP7 -- php 未在浏览器中呈现

bash - 检查 SeLinux 状态

php - 查看 Swagger API 文档

php - 使用 php 从 xml 中删除元素 - 非正统的 xml

linux - 使用另一个应用程序在 docker 中运行 nginx

php - 通过 php curl 的多个请求会影响我的 vps 速度

php - Zend_Form高级用法(数组)

PHP UTF-8编码回显问号

php - Symfony - Guzzle 请求 : cURL error 6: Could not resolve host

linux - 获取错误 chown : invalid group: ‘nobody:nogroup’ while setting up an NFS server drive ownership permission