【问题标题】:Permission denied when I try to get file contents from my home folder当我尝试从我的主文件夹中获取文件内容时权限被拒绝
【发布时间】:2012-05-23 13:54:35
【问题描述】:

我使用名为 system_user 的系统用户运行 cron 作业,并让 cron 作业将其输出保存到我​​的 system_user 主文件夹 /home/system_user/outputDir/outputFile.txt 中的文件 outputFile.txt

这一切正常,但现在我需要在位于/var/www/html/scripts/phpScriptFile.php 的 php 脚本中访问此文件,并且我收到了权限被拒绝错误。

我发现php脚本是用apache用户运行的,所以我这样做了:

sudo chown system_user:apache outputFile.txt

但这并没有帮助。

如果 cron 在 /var/www/html/scripts/ 文件夹中输出文件,那么我不会收到此权限错误。

我试图将 outputFile.txt 移出 /var/www/html 文件夹的原因是,如果我离开它,则可以通过 http 协议访问它,我不希望任何人看到它的内容文件。

请指教。

【问题讨论】:

    标签: php linux permissions


    【解决方案1】:

    可能包含该文件的文件夹中的某些权限不正确。

    另外,可能 apache 用户的组未命名为 apache 或未正确分配组权限。

    重新分配您的用户组:

    sudo chown system_user:system_user outputFile.txt
    

    并测试授予整个路径的一般读取权限:

    chmod o+rx /home/system_user
    chmod o+rx /home/system_user/outputDir
    chmod o+r /home/system_user/outputDir/outputFile.txt
    

    如果这可行(应该可行),那么您可以尝试调查组名是否正确,将访问权限移至组部分。

    【讨论】:

      【解决方案2】:

      outputFile.txt 的权限是什么?

      sudo chown system_user:apache outputFile.txt
      

      这将 system_user 作为所有者,但将组更改为 apache。为此,文件必须至少为 rw-r-----,这可以由 chmod 640 outputFile.txt 完成。

      【讨论】:

      • 权限是-rw-rw-r--
      猜你喜欢
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 2020-05-01
      • 1970-01-01
      相关资源
      最近更新 更多