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

33,340

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: apache

Note 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

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

Share:
33,340
MLSC
Author by

MLSC

Updated on October 14, 2021

Comments

  • MLSC
    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
    MLSC about 8 years
    This is centOs so I think we don't have www-data.
  • Asur
    Asur about 8 years
    @MLSC Then change www-data for apache as mentioned in the httpd wiki fragment
  • chrisweb
    chrisweb about 6 years
    Please no, don't run apache as root, this solves the described problem but is a security risk and would be worse
  • negrotico19
    negrotico19 almost 5 years
    chown: apache.apache: illegal user name