Debian/Ubuntu Tips and Tricks

Debuntu

Debian/Ubuntu Tips and Tricks

How To: Setting up awstats with apache 2 on debian-ubuntu — page 2

Posted by chantra on April 21st, 2006

This entry is part 2 of 2 in the series How To: Setting up awstats with apache 2 on debian-ubuntu

3. Configuring Awstats:

Awstats configuration file are located in /etc/awstats. By default, when calling the URL http://www.mysite.org/awstats/awstats.pl, awstats is looking for the configuration file name after your domain name, namely here /etc/awstats/awstats.www.mysite.org.conf. You can override this by giving awstats an argument named config. For instance http://www.mysite.org/awstats/awstats.pl?config=foobar will indicate awstats to fetch the configuration from /etc/awstats/awstats.foobar.conf.


Let's get back to it. On install, awstats provides a default configuration file named /etc/awstats/awstats.conf. Copy this file to /etc/awstats/awstats.www.mysite.org.conf:

~$sudo cp /etc/awstats/awstats.conf /etc/awstats/awstats.www.mysite.org.conf

and edit the file:

~$sudo vi /etc/awstats/awstats.www.mysite.org.conf

and check for the following lines and edit those for your needs:


LogFile="/var/log/apache2/access.log"
SiteDomain="mysite.org"

This is all setted up, now you need to generate the first stats.

4. Generating the First Stats:

in order to generate the first stats, you need to call the script as root using the following command line:

~:$sudo -u www-data /usr/bin/perl /usr/lib/cgi-bin/awstats.pl -update -config=www.mysite.org

Once this is all processed, check out your stats from http://www.mysite.org/awstats/awstats.pl :D.

5. Automatising the stats generation using Cron:

If we check the file installed by awstats and search for the word cron using the following command line:

~:$dpkg -L awstats | grep cron
/etc/cron.d
/etc/cron.d/awstats

we can see that awstats already installed a cron job which contain:

0,10,20,30,40,50 * * * * 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=awstats -update >/dev/null

which basically check every 10 minutes that file /usr/lib/cgi-bin/awstats.pl is executable AND file /etc/awstats/awstats.conf exists and is a regular file AND file /var/log/apache/access.log is readable, if this is TRUE, it executes awstats.pl with the config awstats.

As the file /etc/awstats/awstats.awstats.conf does not exist, it will take /etc/awstats/awstats.conf by default.

What we can do in the first, is to use that file for our needs. Let say I want update my stats every day at 2am, I will change the line to:

0 2 * * * 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=mysite.com -update >/dev/null

Hope this helped ;)

Recommanded Book:

Series Navigation<< How To: Setting up awstats with apache 2 on debian-ubuntu

2 Responses to “How To: Setting up awstats with apache 2 on debian-ubuntu — page 2”

  1. Thank you!

    This was one of the only tutorials on this subject that actually got everything spot on. Have used this several times on many different servers (all same Debian OS) and has worked every time!

    Just a quick note to users who may use suExec with Apache2 and have encountered the 'Attempt to invoke directory as script' or 'suexec policy violation' errors in their apache error logs. This problem stems from a slight misconfiguration somewhere along the line. This is usually due to suExec trying to use the wrong user to access the cgi-bin directory (/usr/lib/cgi-bin). You need to make sure your Virtual Host is not set to use the root user ( uid:0, gid: 0 ) to execute cgi scripts as this, by default, is not allowed. This problem also presents itself as a '500 Internal Server Error' when trying to visit 'domain.tld/awstats/awstats.pl'.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>