In PHP, I'm receiving this: Warning: fopen(/tmp/mydir/file.txt): failed to open stream: No such file or directory
when calling fopen ('/tmp/mydir/file.txt', "r");
However:
cd /tmp
ls -l .
drwxrwxr-x 2 user 4.0K Aug 19 14:09 mydir
ls -l mydir
-rw-rw-r-- 1 user 41K Aug 19 14:09 file.txt
If I try to do print_r(scandir('/tmp/'));
I get an empty array. Doing print_r(scandir('/tmp/mydir/'));
I get failed to open dir: No such file or directory
. However, doing print_r(scandir('/home/user/'));
returns failed to open dir: Permission denied
. For some reason, directories in /tmp
show no such file or directory, even though they exist. It's also not a permission issue, and if it were, it would (should) produce the permission error.
What am I missing here? Or is this a known bug?
It could be an issue with PrivateTmp
feature: it mounts /tmp and /var/tmp as visible only to that process so every process sees a different virtual /tmp folder.
If you want to change it, you can create /etc/systemd/system/php-fpm.service.d/private-tmp.conf
with contents:
[Service] PrivateTmp=false
Source for the fix: Content of /tmp is not visible from PHP-FPM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With