#native_company# #native_desc#

Using Webalizer to analyze Apache logs Page 4

By Rodney Hampton
on September 5, 2001

Since reading Darrel Brogdon’s article Using PHP
as a Shell Scripting Language
, I have been using PHP for most
scripting tasks. Fortunately, my client had been fairly consistent
in how he had constructed his Servername and ServerAlias directives for
each virtual host. If you are a Perl wonk or a sed fanatic you
could probably do this with fewer lines of code, but I think my PHP
solution is easier to read: Script 1.
Briefly, this script opens the apache configuration file and reads each
line. If the line is a comment, it simply writes the line to the output
file. If the line is not a comment it looks for the first VirtualHost
directive. If it has come to the first VirtualHost directive (which is
usually toward the bottom of most apache configuration files) then it
starts to look for a ServerName directive. When it finds this
directive, it appends the custom logfile directive to the end of the
ServerName line with the appropriate log file name.
After running this script and ensuring that the output is satisfactory,
you can replace your current httpd.conf file. I also like to switch
HostnameLookups to On but this can cause trouble with some high volume
sites because it tells apache to do a DNS lookup for every client that
connects to the webserver.
You can compile webalizer to do
DNS lookups for you when it runs, but this requires
that you to download and compile the Berkeley DB
package available at http://www.sleepycat.com/. See
the DNS.README file that comes with webalizer for more
Don’t forget to restart apache after you finish editing httpd.conf.