为什么file_put_contents

为什么file_put_contents failed to open stream: Permission denied in /home/user/public_html/test.php on line 2

写入的目录已经755权限了,还是写入失败。

 

最近项目迁移服务器,和file_put_contents 有关的都报错了,一般处理的话直接改成文件夹777权限。但是这个是存在安全问题的,虽然这样做很快、一下问题就解决了。但是这个问题的正确处理应该是这样。

 

问题原因:使用了错误用户!例如PHP用户和文件夹所有者不是一个 user.

解决办法:更改一致的用户即可;

You are probably using the wrong user.

Check if php uses the same user which owns the directory you are trying to write.

Php often uses wwwdata so if the directory is chmodded to 755 it means that the user created the directory can write it, but others can only read.

chown to the php user or chmod to 777.

 

文章来源:刘俊涛的博客 欢迎关注公众号、留言、评论,一起学习。

 

若有帮助到您,欢迎点击推荐,您的支持是对我坚持最好的肯定(*^_^*)

猜你喜欢

转载自www.cnblogs.com/lovebing/p/13186541.html