Awstats installation in Ubuntu

Posted under » Ubuntu » Linux » SEO updated on 30 March 2012

Awstats is not new and I have been using it since 2000 because google analytics is risky and slow. The last update was probably in 2007. I chose awstats because it is part of Ubuntu's repositories. Refer to the documentation for Awstats.

Tested installation an Ubuntu 10.10 and 12.04.

How does it work?

It works in Perl. So you have to make it work with Apache. Subject to your version, the location of the files are

The idea is that with one installation of Awstats, you can check the hits of a particular domain by specifying in the parameter like

http://awestats.com/awstats/awstats.pl?config=anoneh.com

Since they will be looking at raw apache log files, it must be processed first. This processing is done by command line by specifying the config files.

/usr/lib/cgi-bin/awstats.pl -config=anoneh.com -update

The config file determine things like

Once processing is done you can then view the stats from your browser.

Common errors

Error: SiteDomain parameter not defined in your config/domain file. 
You must edit it for using this version of AWStats.
Setup ('/etc/awstats/awstats.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

Actual Reason : Log files are not readable because log files are copied or moved. Therefore you must CMOD it to 0755.

Installing Awstats is simple

aptitude install awstats
or 
apt-get install awstats

Install the plugin dependencies

aptitude install libnet-ip-perl
aptitude install libgeo-ipfree-perl

Making it work with Apache

Since awstats is in perl, then you have to configure the cgi location

<VirtualHost *:80>  
  ServerName awestats.com
  ServerAdmin webmaster@awestats.com

Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

  ErrorLog /var/log/apache2/error-awestats.log
  LogLevel warn
  CustomLog /var/log/apache2/access-awestats.log combined
</VirtualHost>

Configuring Awstats

First make a copy

cp /etc/awstats/awstats.conf /etc/awstats/awstats.anoneh.com.conf

Then gedit awstats.anoneh.com.conf

Missing Images

This is because there are 2 configs. One for apache using alias and one for awstats eg. awstats.anoneh.com.conf. It could be "awstats-icon" like above or default "icons" so make sure both are pointing to the same folder.

Now process the logs

You can if you must, combine multiple log files into one by logresolvemerge.pl tool. Don't attempt to "cat" the log files, it won't work.

/usr/share/doc/awstats/examples/logresolvemerge.pl /var/log/apache2/access-anoneh.log.* > combined-anoneh.log

Once the config is done, process the config file by

/usr/lib/cgi-bin/awstats.pl -config=anoneh.com -update

You can also use cron

# update every 10 min
*/10 * * * * root /usr/lib/cgi-bin/awstats.pl -config=anoneh.com -update > /dev/null

Take note it will take a while. Then view your statistics with the processed data using browser

http://awestats.com/awstats/awstats.pl?config=anoneh.com

How to reset awstats

Delete the processed log files in /var/lib/awtstats (directory defined by DirData parameter) using RM although you have to be root.

If awstats doesn't impress you, then you should try something more current. Introducing PIWIK.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data