Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 604
MLSC Avatar asked Mar 08 '16 07:03

MLSC


Video Answer


2 Answers

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  
like image 185
Bart Friederichs Avatar answered Sep 23 '22 07:09

Bart Friederichs


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

like image 44
Asur Avatar answered Sep 24 '22 07:09

Asur