AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1556791
Accepted
Mark J. Bobak
Mark J. Bobak
Asked: 2020-06-01 17:47:57 +0800 CST2020-06-01 17:47:57 +0800 CST 2020-06-01 17:47:57 +0800 CST

在 PHP 中调用 fopen 时,我只收到来自 Apache 的权限被拒绝错误

  • 772

我在通话时被拒绝fopen(),但前提是从 Apache 执行 PHP 脚本。

  • 我尝试过检查和仔细检查权限,甚至尝试在正在写入的文件和包含该文件的目录上设置 777。
  • selinux 被“禁用”。

遇到错误的行是:

$logfile = fopen('/var/log/httpd/shib_session_logs/'.$filename,'a+');

/var/log/httpd/error_log 的错误是:

[Sun May 31 21:33:40.012053 2020] [php7:warn] [pid 30107:tid 140627505252096] [client 10.0.1.206:39032] PHP Warning:  fopen(/var/log/httpd/shib_session_logs/session_log_202061.log): failed to open stream: Permission denied in /var/www/html/shib/logwritter.php on line 9, referer: https://aiqsso.awsapps.com/start

最后,如果我在命令行运行,不涉及 Apache,它工作正常。

这有效:

php index.php

帮助?

添加信息:

这是/etc/httpd/conf.d/php.conf文件:

#
# The following lines prevent .user.ini files from being viewed by Web clients.
#
<Files ".user.ini">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
        Satisfy All
    </IfModule>
</Files>

#
# Allow php to handle Multiviews
#
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

# mod_php options
<IfModule  mod_php7.c>
    #
    # Cause the PHP interpreter to handle files with a .php extension.
    #
    <FilesMatch \.(php|phar)$>
        SetHandler application/x-httpd-php
    </FilesMatch>

    #
    # Uncomment the following lines to allow PHP to pretty-print .phps
    # files as PHP source code:
    #
    #<FilesMatch \.phps$>
    #    SetHandler application/x-httpd-php-source
    #</FilesMatch>

    #
    # Apache specific PHP configuration options
    # those can be override in each configured vhost
    #
    php_value session.save_handler "files"
    php_value session.save_path    "/var/lib/php/session"
    php_value soap.wsdl_cache_dir  "/var/lib/php/wsdlcache"

    #php_value opcache.file_cache   "/var/lib/php/opcache"
</IfModule>

需要帮助请叫我。

linux apache-http-server
  • 1 1 个回答
  • 3801 Views

1 个回答

  • Voted
  1. Best Answer
    Mark J. Bobak
    2020-06-02T17:12:58+08:002020-06-02T17:12:58+08:00

    好的,我想通了。

    主httpd日志目录/var/log/httpd以及该目录中的所有日志都归root. 但是,这些是它httpd自己写的日志。

    apache显然,PHP 读取/写入的文件是在用户和组的支持下进行的,如/etc/httpd/conf/httpd.conf

    User apache
    Group apache
    

    我chown将日志文件和日志文件所在的目录、/var/log/httpd/shib_session_logs、 编辑到apache:apache. 但这并没有完全解决问题,因为保存 PHP 日志文件/var/log/httpd/shib_session_logs的目录 本身就在一个只有访问权限的目录/var/log/httpd中。root所以,我仍然被拒绝许可。当我放松对该目录的读取权限时,一切都开始工作了。

    我将在这里与一些人讨论这个问题,最终,我们可能会将 PHP 日志目录移动到 之外的另一个位置,/var/log/httpd并将权限重置/var/log/httpd为 700。

    无论如何,它有效!

    • 2

相关问题

  • 如何让我的 Linux 机器看起来像是在运行 Windows?

  • 对于 cp 或 mv,是否有等同于 cd - 的东西?

  • 以 root 身份运行 docker 容器

  • 如何在域和 Linux 活动目录中启用指纹传感器

  • 如何在CentOS 7 中将Ctrl+C 永久更改为Ctrl+K?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve