0
votes

I'd like to easily access the logs of a server to interpret them in a way and display that data to a website visitor. How can PHP access the HTTP logs of a server and all data therein?

2
Please pay attention to the suggest prompts when tagging your question. Any tag with a number less than 10 after it's name is probably wrong. Avoid creating new tags. - Joel Coehoorn
But there's a whole badge for creating popular tags, called Taxonomist -- see stackoverflow.com/badges -- so it appears one IS allowed to create new tags! - Robin Rodricks
If they are good tags, but you should really try to fit into existing categories first if you can. Users with < 100 rep aren't allowed to create tags at all any more. - Joel Coehoorn
I was simple creating "good" tags. Such as "server-logs". - Robin Rodricks

2 Answers

3
votes

Easiest way: create a symbolic link from /var/log/apache2/{acces,error,...}.log to a readable dir, e.g: /var/www

3
votes

The server logs are generally just a file that you can read and parse as any other file. Reading it line by line and using split or a regular expression are commonly done.

These can get quite large, though, so it's not unusual to have a separate process that runs once a day or an hour or whatever that updates a summary file, which would then be read by your PHP script. Or often the separate process generates static HTML pages that then just get served. There are many log analyzers that work this way.