PHP无法读取具有读取权限的文件
问题描述:
我有一个具有这些权限的文件(0644)
I have a file with these permissions (0644)
-rw-r--r-- 1 root root
因此,据我了解,任何人都可以读取该文件.
So from my understanding this file should be readable by anyone.
现在我有了以下代码:
file_get_contents('/path/to/file');
这给了我
警告:file_get_contents(...):无法打开流:权限在...中被拒绝
Warning: file_get_contents(...): failed to open stream: Permission denied in ...
我想念什么?
我正在从www-data
下的Web服务器运行它.
I'm running it from a web server under www-data
.
答
可能的原因与解决方案:
Possible causes with solutions:
解决方案:为整个文件夹层次结构配置正确的权限.另请参见此注释在PHP安全模式下.
Solution: Configure the correct permission rights for the whole folder hierarchy. Also see this remark on PHP safe mode.
这很奇怪,但是这种情况发生.
解决方案:配置文件和文件夹的执行权限.
Solution: Configure execution rights for file and folders.
解决方案:正确配置它们.
Solution: Configure them properly.