Posted by k2 on Mon 24 Oct 2005 at 00:05
I have noticed people asking questions about web server statistics programs on debian-user mailing list. So I'm posting a compendious version of my original(personal) documentation on how to setup awstats on Debian GNU/Linux for generating statistics for Apache web server. The article focuses on the steps required to get awstats running on your server, setting up cron job for it, and reconfiguring logrotate for apache to take care of lost logs.
The first step is to install awstats using apt or dselect or your favourite package management software. With apt just execute (as root):
~# apt-get install awstats
Run the awstats configure script to setup awstats for the domain you want to monitor. Remember to repeat the configuration process for each domain you want to monitor.
~# cd /usr/share/doc/awstats/examples/ ~#/usr/share/doc/awstats/examples$ perl awstats_configure.pl
Answer the questions asked by the script in which you will need to know the full configuration file path of your web server(e.g. /etc/apache/httpd.conf), and the name of your domain for which you are setting up awstats( full-domain-name in this article).
While running the script it will complain that it is not being run from the default location (/usr/local/awstats). Answer yes to the prompt to run from the non-standard location as the official Debian package of awstats places the script in /usr/share/doc/awstats/examples/ which is the Debian way.(See the original for detailed script output)
After the script exits, you should set up an alias for awstats-icons in httpd.conf. Inserted it in the Aliases section. The awstats_configure.pl script adds it in the end of httpd.conf - comment/remove it.
Your entry for /awstats-icon/ in the Aliases section should look like:
Alias /awstats-icon/ /usr/share/awstats/icon/ <Directory /usr/share/awstats/icon> Options None AllowOverride None Order allow,deny Allow from all </Directory>
Now you can restart apache:
~# /etc/init.d/apache restart
Edit the awstats' domain configuration file you just created /etc/awstats/awstats.full-domain-name.conf to have LogFormat=1. Default "LogFormat=4" does not show Browsers, OS, keywords, etc. Do make sure that the parameter SiteDomain has a value of the domain to monitor. Generate stats the first time by using the following command. (You can allow awstats to read your apache log file by changing permissions. Run "chmod o+r /var/log/apache/access.log"):
~#/usr/lib/cgi-bin/awstats.pl -config=awstats.full-domain-name.conf Update for config "/etc/awstats/awstats.full-domain-name.conf" With data in log file "/var/log/apache/access.log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 60 Found 0 dropped records, Found 0 corrupted records, Found 0 old records, Found 60 new qualified records.
You can now check the stats in your browser by point it to http://full-domain-name/cgi-bin/awstats.pl?config=full-domain-name.
Set up cron job for awstats as below:
3,33 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=full-domain-name -update >/dev/null
Setup a prerotate task to run awstats.pl before log rotate and change permissions of log file to 644. Please comment on this as making access.log 644 is basically allowing access to anybody to read the file. Is there another way to do it more securely?
/var/log/apache/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
prerotate
/usr/lib/cgi-bin/awstats.pl -config=ghaint.no-ip.org -update
endscript
postrotate
if [ -f /var/run/apache.pid ]; then \
if [ -x /usr/sbin/invoke-rc.d ]; then \
invoke-rc.d apache reload > /dev/null; \
else \
/etc/init.d/apache reload > /dev/null; \
fi; \
fi;
endscript
}
This should get awstats running automatically every half an hour with the statistics available via your web browser. After finishing you might want to go back to the configuration file /etc/awstats/awstats.full-domain-name.conf to do more tweaking. Reading the documentation in /usr/share/doc/awstats/ is also recommended.
This article can be found online at the Debian Administration website at the following bookmarkable URL (along with associated comments):
This article is copyright 2005 k2 - please ask for permission to republish or translate.