PHP 报文件写入无权限 file_put_contents failed to open stream: Permission denied in xxxxx on line 2

使用命令查看下权限:ls -l ./[target_dir]

 这个文件权限变成root了,不再是apache了。

因为在项目中git了下,git执行在root用户下的。应该就是这个原因了。

解决办法:

对整个目录先设置下权限 chown -R apache:apache [target_dir](权限还原成apache) 

然后每次执行 git 命令都用 apache 的用户执行 sudo -u apache git reset --hard 977e75b

原文地址:https://www.cnblogs.com/Denny_Yang/p/14913592.html