2017-08-05 16:35
浏览 79

Fedora PHP“无法打开流:权限被拒绝”

So I've got Apache on web server running Fedora. I'm trying to write into the text file.

$file = fopen(APP_DIR."/resources/version.txt", "w");
fwrite($file, $_POST['versionWrite'].PHP_EOL);

And when I execute the code, I get this:

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

This happens in every script working with files. And I have no idea what shall I do to grant Apache permissions to edit files.

Thanks for your time :).

图片转代码服务由CSDN问答提供 功能建议

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

  if(!empty($ _ POST ['versionWrite'])){
 $ file = fopen(APP_DIR。“  /resources/version.txt“,”w“); 
fwrite($ file,$ _POST ['versionWrite']。PHP_EOL); 
 nclclose($ file); 


 警告:fopen(/var/www/spumprnagle/resources/version.txt): 无法打开流:第28行/var/www/spumprnagle/head.php中的权限被拒绝
警告:fwrite()要求参数1为资源,在/var/www/spumprnagle/head.php中给出布尔值 第29行

这在每个使用文件的脚本中都会发生。 我不知道如何授予Apache编辑文件的权限。


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongyan8929 2017-08-05 16:50

    Problem: The apache user doesn't have the permission to write file.


    chown -R apache:apache path/to/directory

    where apache is the default user for fedora and path/to/directory is the path of the directory containing the files with you want to write.

    If you want to give the permission to a single file then omit -R

    点赞 打赏 评论
  • dsh77114 2017-08-05 16:40

    I would start by checking permissions on the file /var/www/spumprnagle/resources/version.txt to ensure that it's writeable by the web user. Since you tagged fedora here, I believe that's usually the apache user, so try chown apache:apache /var/www/spumprnagle/resources/version.txt.

    If you're unsure of permission setting you can always temporarily set 777, e.g. chmod 777 /var/www/spumprnagle/resources/version.txt. If that resolves the issue, you can adjust the permissions down to something more reasonable (644).

    点赞 打赏 评论

相关推荐 更多相似问题