Httpd – Using sudo /etc/init.d/httpd start complains for log file rights

apache-2.2httpdsudo

I created a custom log directory with the root account, and chmoded it to 777 teporarily.

ls -la /var/mylogs/log/
total 16
drwxrwxrwx 2 root root 4096 Jun 24 06:27 .
drwxr-xr-x 5 root root 4096 Jun 24 06:25 ..

When I try to start the service from a user (lets say "myuser", which is in the sudoers files as myuser ALL=(ALL) ALL), it fails because of the permissions :

sudo /etc/init.d/httpd start

Starting httpd: (13)Permission denied: httpd: could not open error log file /var/mylogs/log/httpd_error.log.
Unable to open logs

However, the following is successfull :

sudo bash
/etc/init.d/http start

So I guess these two methods are not equivalent, although to me doing sudo was the same than logging into the root account and issuing the commands.

Any clue ?

Thank you !

Best Answer

The apache2 process should be owner of logging directory instead of root. You can fix this issue by changing owner of log directory (i.e. www-data or group to which apache2 belongs to)