php 权限被拒绝:httpd:无法打开错误日志文件 /etc/httpd/logs/error_log

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35861728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:36:34  来源:igfitidea点击:

Permission denied: httpd: could not open error log file /etc/httpd/logs/error_log

phpapachehttpd.confselinux

提问by MLSC

When I want to restart the httpd searvice on centOS 6.7 I have the following error:

当我想在 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]

This is error_log:

这是错误日志:

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

I disabled selinux also.

我也禁用了 selinux。

What is the problem?

问题是什么?

回答by Bart Friederichs

httpdruns probably as user apacheor user httpd. Your log is owned and only writable by root. Change ownership of your logfile to make this work.

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

This should do the trick:

这应该可以解决问题:

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

回答by Asur

Probably you should change the group of that forder to apache, it's not recommended to have root as owner of server stuff. Anyway apache should change that on his own after http starts...

可能您应该将该组更改为 apache,不建议将 root 作为服务器内容的所有者。无论如何 apache 应该在 http 启动后自己改变它......

From httpd Wiki:

来自httpd 维基

Before we start, we need to be aware that the Apache HTTP server (httpd) runs as a particular user and group.

On Linux as well as most other Unix-like systems, httpd is started as the "root" user; UID=root, GID=root. This is necessary because only this user can bind to port 80 and 443 (anything below 1024 in fact).

After http starts and binds to its ports (defined by the Listen statments in httpd.conf), it changes user to that specified in httpd.conf. Typically:

User: apache
Group: apache

Note that Debian based systems, including Ubuntu, use "www-data" instead.

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

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

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

用户:apache
组:apache

请注意,基于 Debian 的系统(包括 Ubuntu)使用“www-data”代替。

As a possible solution you should add yourself into the group apache

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

usermod -a -G apache (username)

Then:

然后:

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

Anyway that's weird... tell me if this solved your issue, if it didn't I will edit it as long as you provide me further information :)

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

回答by eshraiman

Just run it as super user:

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

service httpd start

Starting httpd: (13)Permission denied: httpd: could not open error log file /etc/httpd/logs/error_log.

Unable to open logs [FAILED]

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

无法打开日志 [失败]

sudo service httpd start

Starting httpd: [ OK ]

启动httpd:[确定]