Being able to track your web statistics is important for commercial sites. For personal sites it may not be as important, but it still nice to know where people are coming from and what they are looking for.
There are a number of open source log analysers that work with Apache, however my preferred choice is Awstats.
It may not be able to give the same level of detail as a commercial package such as Urchin, but it provides more than enough detail for most purposes.
On Ubuntu you can install awstats via apt:
apt-get install awstats
This will install the base package however, if you want to lever its full power you will need to install a couple of extra Perl modules.
apt-get install libnet-ip-perl
If you would like to see which countries your visitors are based in then you should look at one of the IP to Country plugins which will give you a Geo IP lookup.
You can choose between either geoipfree or GeoIp.
Other useful plugins are:
- Plugin: HostInfo – which gives you a popup whois window
- Plugin: IPv6 – adds IPv6 support
- Plugin: Tooltips – confused by all the information? This will take away the mystery 🙂
On rpm-based system there is a handy little perl script that walks you through the initial configuration. On Ubuntu you have to do it by hand, however most of the configuration is self-explanatory.
Simply copy the provided sample config to a new config file:
cp awstats.conf awstats.yoursite.tld.conf
NB: You will need a separate configuration file for each vhost you wish to examine.
Edit the conf file to match your site’s setup. Important things to pay attention to are any domain aliases, the location of the log files and any IPs you wish to ignore (eg. your own)
You can also decide which optional plugins you want to load. Simply add a line to invoke each one:
LoadPlugin="geoipfree"
LoadPlugin="ipv6"
LoadPlugin="Tooltips"
geoipfree requires an extra perl module. On ubuntu the package is called libgeo-ipfree-perl
You are almost ready!
You now need to configure Apache to allow access to your awstats pages.
Rather than messing about with my main Apache config file I found it neater to place the awstats specific information in an external file called awstats.conf:
Options None
AllowOverride None
Order allow,deny
Allow from all
Alias /awstatsicons/ /usr/share/awstats/icon/
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
Then use an include directive in your main Apache config (apache2.conf):
Include /etc/apache2/awstats.conf
You then need to add it in to your vhost:
ScriptAlias /whereyouwanttoaccessit/ /usr/lib/cgi-bin/
If you navigate to:
http://www.yourdomain.tld/whereyouwanttoaccessit/awstats.pl?config=yourdomain.tld
You *should* be able to access your stats.
Of course you’ll need to actually generate the stats first:
/usr/lib/cgi-bin/awstats.pl -config=yourdomain.tld -update
I would recommend you run this from the command line once to create the first set of stats and then add a cronjob:
crontab -e
0,10,20,30,40,50 * * * * /usr/lib/cgi-bin/awstats.pl -config=yourdomain.tld -update >/dev/null
wq
This will update your stats every 10 minutes, which means that you’ll only have to update a few lines at a time. If your site is busy this makes sense 🙂
The last part of the line is important:
>/dev/null
By default cron emails the user each time it runs. You really don’t want 6 emails an hour telling you that Awstats has run 🙂
NB: This works for me. Your mileage may vary. If I’ve left out anything blatantly obvious please let me know
Bernhard says
Hi Michelle
why didn’t you put awstats into /etc/apache2/conf.d? Then it is included automatically …
blacknight says
Bernhard
The way I set it up it works 🙂
Michele
David says
I see that you configuration does not show up properly in the blog.
The tags are completely missing (seems your blog cleans those from your postings).
Also I put this line:
Alias /awstats-icon/ /usr/share/awstats/icon/
instead of:
Alias /awstatsicons/ /usr/share/awstats/icon/
otherwise icons don’t show up for me.
roger says
I played around with icon settings too. It just needs to match with the value in the config file.
DirIcons=”/awstats-icons” is the default.
And the config file only needs to match your config parameter, not you host or domain. For example, I can create a config file /etc/awstats./conf. I just need to put config= everywhere.
roger says
lets repeat the last part:
For example, I can create a config file /etc/awstats.whatever.conf. I just need to put config=whatever everywhere.
Zsolt says
Thx Michele!
With the help od your little HowTo it was an easy task to set up Awstats on my server….
Even dough I use Debian ^^.
@ David If you wouldn’t have mentioned it, I would have never taken a closer look to this blogs page source, and probably would have missed the Directory tags…
Thank you too…
Zsolt
Brad says
works great!
One note however, for the tooltips plugin, the plugin name is a lower case t. You will get an error if you use:
LoadPlugin=”Tooltips”
use
LoadPlugin=”tooltips”
instead!
Seb says
I have a problem:
even if awstats woked for a few good months, it stoped working.
not sure hy, but probably after a update or something on Ubuntu, awstats report the error:
Not Found
The requested URL /cgi-bin/awstats.pl was not found on this server.
Do you have any idea where to look for a solution?
michele says
Seb – Sounds like your apache configuration has changed. You may have overwritten one of the configuration files during an upgrade
Seb says
Michele,
yes, this is true and I fixed teh problem, adding ScriptAlist to cgi-bin
however now I see a diff problem, and this is related to the fact that there are no records in /var/log/apache2/access.log file.
This is also since my last upgrade – I see access.log file unchanged since my upgrade.
But can’t figure out why as the apache2.conf file has the LogFormat entryes.
Daniel says
Michele, my Ubuntu package already provided a /etc/cron.d/awstats config file? It’s different from the one you typed.
michele says
Daniel
Which version of Ubuntu and Awstats are you using?
What’s in the config file?
Michele
Daniel says
I’m using the awstats 6.5 on Dapper.
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
I’ve modified the -config entry to suit my website’s config. In your example it would be yourdomain.tld.
Could you please look at what David has already mentioned? Your Apache config directives are treated as HTML instead of text.
Try replacing ” with ‘>’.
THG says
Daniel,
the code points to the /var/log/apache directory instead of /var/log/apache2/access.log
Mathew says
Nice article, thanx. It was help me much…
Is there any change if i have debian?
Alex Robar says
Great article Michele. I just setup AWStats on Ubuntu 6.06 using your guide and it works great! Thanks for writing this.
John Pye says
geoipfree says I’m in China. Which I’m not. I suspect its database is out of date enough not to be worth bothering with.
Trond Egil says
Hello.
Can I set ut an AWStats Server that reads Apache logs on another server ?
How do I do this, as I can’t install AWStats on the Apache web server.
michele says
Trond
I don’t think you could get it to read logs from a remote server “live”, but you could probably copy the logs across and do it that way. Of course someone else may know of a way of doing it
Michele
michele says
@John
The Maxmind DB works well
If you need Geoip you will end up paying for an up to date one
Michele
Trond Egil says
Hello.
I can’t get icons to show.
Can someone please show me how the /etc/awstats/awstats.conf file looks like.
I get error every time Apache2 restarts.
I have also tried to include everything in apache2.conf, but no luck.
Please help me….
gogan says
I’m trying to setup my apache2 on ubuntu breezy, I’ve followed your steps but I get this error when I ran
/usr/lib/cgi-bin/awstats.pl -config=gogan.homelinux.org -update
Error: Plugin load for plugin ‘geoip’ failed with return code: Error: Can’t locate Geo/IP/PurePerl.pm in @INC
Thanks in advance
michele says
Gogan – Have you installed the geoip module?
neaveru says
Gogan: I had the same issue. Try the following:
sudo apt-get install libgeo-ipfree-perl
Also, for crontab, instead of
0,10,20,30,40,50 …
You can replace it with:
*/10 …
Cheers
http://neaveru.blogspot.com
neaveru says
Sorry for the double post, just wanted to add for Trond Egil:
To get icons to work, this worked for me, in my apache2.conf:
Alias /awstats-icon/ /usr/share/awstats/icon/