PHP脚本无法检测Web根目录外文件的排查求助
PHP脚本无法访问Web根目录外文件的排查疑问
环境信息
- PHP 8.1.27
- Nginx 1.24.0
最小复现场景
脚本路径:/var/www/testing/index.php,代码如下:
<?php $devPath = '/dev/dri/renderD128'; if (!file_exists($devPath)) { echo "File does not exist!"; } elseif (!is_readable($devPath)) { echo "File is not readable!"; } else { echo "All good!"; } clearstatcache(); ?>
问题现象
- 执行脚本后输出
File does not exist! - 将
$devPath改为Web根目录内的/var/www/testing/testing时,输出All good! - 测试
/tmp/testing文件时,同样输出File does not exist!
已完成的验证
- 目标文件
/dev/dri/renderD128、/tmp/testing确实存在 http用户属于render组- PHP-FPM的
testing池进程由http用户运行 - 已确认使用正确的
php-fpm.conf配置文件
验证命令及结果:
# ls -lah /dev/dri/renderD128 crw-rw-rw- 1 root render 226, 128 Feb 2 22:49 /dev/dri/renderD128 # groups http render redis http # ps aux | grep php | grep testing http 116949 0.0 0.0 79256 10036 ? S 18:24 0:00 php-fpm: pool testing # ps aux | grep php | grep master root 116935 0.0 0.0 79404 19676 ? Ss 18:24 0:00 php-fpm: master process (/etc/php-legacy/php-fpm.conf)
额外测试异常
添加open_basedir指令(值为/var/www/testing:/dev/dri/renderD128)后,出现警告:
Warning: file_exists(): open_basedir restriction in effect. File(/dev/dri/renderD128) is not within the allowed path(s): (/var/www/testing:/dev/dri/renderD128) in /var/www/testing/index.php on line 3
- 使用
scandir扫描/dev/dri/时,提示权限不足或目录不存在 - 扫描
/dev/时能看到部分内容,但看不到dri目录
已确认/dev、/dev/dri、/tmp的权限设置符合要求,但问题仍未解决,请问可能的原因是什么?
内容的提问来源于stack exchange,提问作者Christian Eriksson
相关产品推荐
相关产品推荐

