php - 软呢帽 PHP "failed to open stream: Permission denied"

标签 php linux error-handling fedora

所以我在运行 Fedora 的 Web 服务器上安装了 Apache。我正在尝试写入文本文件。

if(!empty($_POST['versionWrite'])){
$file = fopen(APP_DIR."/resources/version.txt", "w");
fwrite($file, $_POST['versionWrite'].PHP_EOL);
fclose($file);
}

当我执行代码时,我得到了这个:

Warning: fopen(/var/www/spumprnagle/resources/version.txt): failed to open stream: Permission denied in /var/www/spumprnagle/head.php on line 28

Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/spumprnagle/head.php on line 29

Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/spumprnagle/head.php on line 30

这发生在每个处理文件的脚本中。而且我不知道该怎么做才能授予 Apache 编辑文件的权限。

感谢您的宝贵时间 :)。

最佳答案

好的,我为那些在 Fedora 上搜索答案的人添加了这个答案。我将文件权限更改为 777 并将文件所有权更改为 apache:apache 但它一直抛出相同的错误。最后我发现在某些版本的 Fedora 中 SElinux 会阻止 Httpd 写入文件。解决方案是禁用 SElinux,如下所示:

 vim /etc/selinux/config 

然后按如下方式编辑文件:

 SELINUX=disabled 

然后重启。 它对我有用。 快乐编码。

关于php - 软呢帽 PHP "failed to open stream: Permission denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45524175/

相关文章:

linux - 如何使用Linux命令行跨子目录查找相似的文件名?

linux - 用另一个文件的内容替换文件的所有内容

android - 资源链接失败/Android Studio College Project

php - 表格 html/CSS 输出错误 : unexpected T_STRING

php - 在数组循环内显示数组

c++ - 命令行错误中缺少DSO(动态共享库)的解决方案是什么?

swift - 对 Swift 3 中的错误处理感到困惑

c# - asp.net webforms 在代码隐藏中处理 404 notfound 错误?

Php 不会在递归 foreach 循环中中断

php - Paypal (PHP): match customer with order