It's possible that the permissions are not sufficient to write into that file; you also have to make sure that the directory is reachable too.
Example how it was on my system (this was standard Debian wheezy installation):
$ ls -ld /var/log/apache2/
drwxr-x--- 2 root adm 4096 Sep 4 15:59 /var/log/apache2/
$ ls -ld /var/log/apache2/php-error.log
-rw-r--r-- 1 www-data www-data 0 Jul 23 11:07 /var/log/apache2/php-error.log
This didn't work, because the directory containing the php-error.log
wasn't reachable. Luckily mod_php (or apache2?) falls back to write it into the VirtualHosts error log.
In my case, it was easily fixable by applying chmod o+rx /var/log/apache2/
but your security considerations may vary. After the fix:
$ ls -ld /var/log/apache2/
drwxr-xr-x 2 root adm 4096 Sep 4 15:59 /var/log/apache2/
And with that change it worked.
PS: First, I had the same problem you had, couldn't solve it within a day. Google searching turned nothing up. Thought about writing a question on serverfault. While preparing title I got the suggestions and yours was the second hit. I realized I would write a duplicate question so I thought I write a comment at yours. But then I wanted to write more and thought about writing an answer which wouldn't solve the problem but would lead to my perspective too, maybe someone else could help. And while preparing the answer, I discovered the solution. This is absolutely fantastic about ... well, anything here. serverfault/stackexchange helped me find the solution on my own implicitly with the help of others. Can't get better, I guess (besides solving it on my own).
Best Answer
Apache keeps its log files open so deleting a log file stops apache from logging to it, since the old file descriptor now points to a deleted inode.
You should rotate/delete/truncate the log file, re-create it with the correct ownership and permissions, and then issue an
apachectl graceful
to reload.Alternatively, apache can log errors to syslog; this does not suffer from the same limitations.