Ho trovato un comportamento strano riguardante la cartella php
e /tmp
. Php utilizza un'altra cartella quando funziona con /tmp
. Php 5.6.7, nginx, php-fpm.Php ha il proprio/tmp in/tmp/systemd-private-nABCDE/tmp quando si accede tramite nginx
Eseguo lo stesso script in due modi: tramite browser e tramite shell. Ma quando si è lanciato via browser, il file non è nella cartella reale /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)
Dove è il file? In/tmp
$ find/-name 185617.txt
/tmp/185617.txt
Se l'accesso tramite http://myserver.ru/script.php
ottengo
File /tmp/185212.txt
bool(true)
string(38) "CentOS Linux release 7.0.1406 (Core)
Ma dove è il file?
$ find/-name 185212.txt
/tmp/systemd-private-nABCDE/tmp/185212.txt
Perché php pensa che /tmp
dovrebbe essere in /tmp/systemd-private-nABCDE/tmp
?
Hai ragione, ma questo è 'php-fpm', non' nginx'. Ho cambiato il file '/ usr/lib/systemd/system/php-fpm.service' line' PrivateTmp = true' in 'PrivateTmp = false'. Ora php usa la cartella '/ tmp' corretta. –
wow, questo è geniale. proprio quello che stavamo cercando da 2 giorni :) –