1

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?

0

3 Answers 3

2

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
</VirtualHost>

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

/path/to/webroot/.htaccess:

php_value error_log /home/user/phperrorlog-colleagues.vhost.com
2
  • +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. Dec 20, 2010 at 19:48
  • +1 accepted. I actually prefer this answer because of the fine control via php log output. Dec 21, 2010 at 9:59
2

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
  • +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. Dec 20, 2010 at 19:49
1

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.

2
  • +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. Dec 20, 2010 at 19:47
  • Good answer, but as said, limitation is that upgrade resets permissions. Dec 21, 2010 at 9:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .