PHP can't read file with read permissions

≡放荡痞女 提交于 2019-12-11 08:54:36

问题


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.

Now I have this code:

file_get_contents('/path/to/file');

And it is giving me this

Warning: file_get_contents(...): failed to open stream: Permission denied in ...

What am I missing?

I'm running it from a web server under www-data.


回答1:


Possible causes with solutions:

Reading permissions are required for folders in the file path

Solution: Configure the correct permission rights for the whole folder hierarchy. Also see this remark on PHP safe mode.

Execution permissions are required for reading the file

It's strange, but this happens.

Solution: Configure execution rights for file and folders.

Access control lists for the server are not configured

Solution: Configure them properly.




回答2:


Login with root user and execute the command:

chmod -R 777 /path/to/file

OR

chmod -R 777 /path


来源:https://stackoverflow.com/questions/39846827/php-cant-read-file-with-read-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!