I'd like to be able to display the error_log as a web page so that a colleague (without root access) can view this for troubleshooting their PHP development.

On my CentOS 5.x machine the error log is at: /var/log/httpd/error_log and the directories are root access only.

I'd write a CGI script to display the log but as this runs in the apache process this is not root so the log file cannot be accessed. (Tried it). What puzzles me is that somehow apache can write to it to log errors even though the containing directories are root access.

How could I achieve my aim? Or can you suggest an alternative please?


Actually, I probably wouldn't use my other answer in some situations, but I'll keep it there for reference.

If your colleague has been given their own VirtualHost, I would set that virtualhost to output their logs to a different directory, so that they would only see errors for their system:

<VirtualHost *:80>
    ServerName colleagues.vhost.com
    DocumentRoot ...
    ErrorLog /home/user/errorlog-colleagues.vhost.com

Alternatively, if .htaccess files are enabled, get them to simply output their php error logs to a location they want, e.g.:


php_value error_log /home/user/phperrorlog-colleagues.vhost.com
  • +1 for demonstrating the ability to change path in the apache directives, I've done a bit of work in this area (for other things), so am not too afraid of dabbling here. Thanks. – therobyouknow Dec 20 '10 at 19:48
  • +1 accepted. I actually prefer this answer because of the fine control via php log output. – therobyouknow Dec 21 '10 at 9:59

you can change the permissions on the file ... if not you can have a cron job that runs every minute doing a rsync from the apache log file to a different file (where you can set permissions to read ) and then display it on the web page.

there are also ways where you can change the logging mechanism for apache, it depends by your ability to change the configuration.

  • +1 I considered the permissions, if someone says the same then it might be a safe option, going the 'crowdsense' way. +1 also for the rsync option. – therobyouknow Dec 20 '10 at 19:49

I would change the permissions on the /var/log/httpd directory to solve the problem of accessing the files from the console.

add a new group and add the user to it:

groupadd apache-logs
usermod -a -G apache-logs user
chgrp apache-logs /var/log/httpd
chmod g+rx /var/log/httpd

or if you are happy with any user on your system viewing the logs, just:

chmod go+rx /var/log/httpd

Whichever you do, it will reset to the original permissions if you upgrade httpd. It shouldn't change otherwise.

Also, the reason why apache can write to the logs with the default permissions is because the log files are opened by apache whilst it runs as root. As soon as apache is fully loaded, it will change its user to apache, but will continue to have open log files.

  • +1 this looks like the best answer as it covers the most of what I asked, I'll have another read and think it through a little bit later. Thanks very much for now. – therobyouknow Dec 20 '10 at 19:47
  • Good answer, but as said, limitation is that upgrade resets permissions. – therobyouknow Dec 21 '10 at 9:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.