Permission denied: httpd: could not open error log file /etc/httpd/logs/error_log
Solution 1
httpd
probably runs as user apache
or user httpd
. Your log is owned and only writable by root
. Change ownership of your log file to make this work.
This should do the trick:
~# chown apache:apache /etc/httpd/logs/error_log
Solution 2
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...
From httpd Wiki:
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: apacheNote that Debian based systems, including Ubuntu, use "www-data" instead.
As a possible solution you should add yourself into the group 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 :)
Solution 3
In CentOS 7
Try disabling SElinux and then reboot then
systemctl restart httpd
Note: never leave SElinux disabled. If the problem is solved then enable(enforce) it and then enable httpd in SElinux
MLSC
Updated on October 14, 2021Comments
-
MLSC over 2 years
When I want to restart the httpd searvice on centOS 6.7 I have the following error:
/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.
What is the problem?
-
MLSC about 8 yearsThis is centOs so I think we don't have
www-data
. -
Asur about 8 years@MLSC Then change www-data for apache as mentioned in the httpd wiki fragment
-
chrisweb about 6 yearsPlease no, don't run apache as root, this solves the described problem but is a security risk and would be worse
-
negrotico19 almost 5 yearschown: apache.apache: illegal user name