【问题标题】:Permission denied: httpd: could not open error log file /etc/httpd/logs/error_log权限被拒绝:httpd:无法打开错误日志文件 /etc/httpd/logs/error_log
【发布时间】:2016-06-22 01:33:41
【问题描述】:

当我想在 centOS 6.7 上重新启动 httpd 服务时,出现以下错误:

/etc/init.d/httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: (13)Permission denied: httpd: could not open error log file /etc/httpd/logs/error_log.
Unable to open logs
                                                           [FAILED]

这是错误日志:

ls -Z /etc/httpd/logs/error_log
-rw-r--r--. root root unconfined_u:object_r:var_t:s0   /etc/httpd/logs/error_log

我也禁用了 selinux。

有什么问题?

【问题讨论】:

    标签: php apache httpd.conf selinux


    【解决方案1】:

    httpd 可能以用户 apache 或用户 httpd 的身份运行。您的日志由root 拥有并且只能由root 写入。更改日志文件的所有权以使其正常工作。

    这应该可以解决问题:

    ~# chown apache:apache /etc/httpd/logs/error_log  
    

    【讨论】:

    • chown: apache.apache: 非法用户名
    【解决方案2】:

    也许你应该把那个forder的组改为apache,不建议让root作为服务器的所有者。无论如何,apache 应该在 http 启动后自行更改...

    来自httpd Wiki

    在开始之前,我们需要知道 Apache HTTP 服务器 (httpd) 作为特定用户和组运行。

    在 Linux 以及大多数其他类 Unix 系统上,httpd 以 “根”用户; UID=根,GID=根。这是必要的,因为只有 此用户可以绑定到端口 80 和 443(实际上是低于 1024 的任何端口)。

    http 启动并绑定到它的端口后(由 Listen 定义 httpd.conf 中的语句),它将用户更改为中指定的用户 httpd.conf。通常:

    用户:阿帕奇
    组:阿帕奇

    请注意,基于 Debian 的系统,包括 Ubuntu,请改用“www-data”。

    作为一种可能的解决方案,您应该将自己添加到组 apache 中

    usermod -a -G apache (username)
    

    然后:

    chgrp apache (folderPath)
    chmod g+rwxs (folderPath)  
    

    无论如何这很奇怪...告诉我这是否解决了您的问题,如果没有,只要您提供更多信息,我就会对其进行编辑:)

    【讨论】:

    • 这是 centOs,所以我想我们没有 www-data
    • @MLSC 然后更改 httpd wiki 片段中提到的 apache 的 www-data
    【解决方案3】:

    只需以超级用户身份运行即可:

    service httpd start
    

    正在启动 httpd: (13)Permission denied: httpd: could not open error log file /etc/httpd/logs/error_log.

    无法打开日志 [FAILED]

    sudo service httpd start
    

    启动httpd:[确定]

    【讨论】:

    • 请不要,不要以 root 身份运行 apache,这可以解决所描述的问题,但存在安全风险并且会更糟
    【解决方案4】:

    在 CentOS 7 中

    尝试禁用 SElinux 然后重启

    systemctl 重启 httpd

    注意:永远不要禁用 SElinux。如果问题解决了,则启用(强制)它,然后在 SElinux 中启用 httpd

    https://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/

    【讨论】:

      猜你喜欢
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      • 2018-05-06
      • 2018-10-03
      相关资源
      最近更新 更多