I have installed AWStats on my web server and posted the following guide to help others.
A mini Howto tutorial - Getting AWSTATS working with APACHE2 in UBUNTU Linux.
Proud of my little ADSL connected web server built on an old Gateway P200 was I, that I felt the need to add some stats pages. After under a minute of detailed research I decided to go for AWSTATS because it just looked better.
Diving right in I did a $ sudo apt-get install awstats and was happy to find a package available and watched it install without any fuss.
Now what? I suppose I’ll have to read some documentation so went to www.awstats.org to find some interesting background reading and very little detail that matched my install. Where were wwwroot and the tools directory all the documententation kept referring to?
After 30 minutes of googling and forum searching I found a number of documents that just confused me so decided then if I got this thing going, I would write it up.
Well it works just fine now so true to my word here is what I had to do. I wish I had bookmarked some of the sites I got useful information from, just in a hurry I suppose but I didn’t other than one which was very useful, posted by anniec and gave me more than 90% of what I needed. LINK
Before running the ./configure.pl script you needs to get your directories in shape and make a backup of your Apache2 config file as it is modified during this process.
$sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.orig
AWSTATS in ubunto seems to dump all the files into /usr/share/doc/awstats/examples so step one was to copy them all over to the documented directory /usr/local/awstats.
$ sudo cp /usr/share/doc/awstats/examples
You can use mv (move) as well, I just wasn’t sure what I was doing so wanted to keep a virgin copy at hand and maybe Ubuntu may yet need it.
In this directory you will find a compressed copy of the main config file called awstats.model.conf.gz. You need to uncompress this with
$ sudo gunzip awstats.model.conf.gz which will give you a copy of awstats.model.conf.
I made a backup $ sudo cp awstats.model.conf awstats.model.conf.orig then copied it to /usr/local/awstats.
I then followed anniec’s instructions more or less, but modifying them for Apache2 rather than Apache.
$ sudo mkdir wwwroot
$ sudo mkdir wwwroot/cgi-bin
Now we need to run the perl script, which immediately failed because it cannot find httpd.conf.
This is because Apache2 in Ubunto’s default configuration is called apache2.conf.
You just need to enter this location after the script complains about not finding httpd.conf.
$ cd /usr/local/awstats/
$ sudo ./configure.pl
Enter /etc/apache2/apache2.conf when prompted for httpd.conf location and give the configuration file a unique name such as your domain name. If your unique name given was foo then you will end up with a file called awstats.foo.conf.
Once run successfully the perl script will add some lines to apache2.conf. The final part of this file will have these lines added to it. Don’t bother restarting Apache just yet.
# Directives to allow use of AWStats as a CGI
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
# This is to permit URL access to scripts/files in AWStats directory.
Allow from all
These lines added to apache2.conf do not match the directory structure so I added the recommended links to the real ones modifying again for the Apache2 structure.
$ sudo mv awstats.model.conf wwwroot/cgi-bin
$ sudo ln -s /usr/local/awstats/css/ wwwroot/
$ sudo ln -s /usr/share/awstats/* wwwroot/
$ sudo ln -s /usr/lib/cgi-bin/awstats.pl wwwroot/cgi-bin/
$ sudo chown -R --dereference www-data:www-data wwwroot
$ sudo chown -R www-data:www-data /var/lib/awstats/
$ sudo chown root:www-data /var/log/apache2/access.log
Now is the time to restart Apache2. The method I used was to issue the command
$ sudo /etc/init.d/apache2 restart
If all is well you will get a little [ok] in the right hand side. So far so good we need to now modify the awstats configuration file.
You now need to edit this with an editor. I used vi. If you have not used vi before or have been scared by the stories do not fear and follow these instructions.
$sudo vi /etc/awstats/awstats.foo.conf
If all is well you will see the configuration file come up – if you see a blank page you have made an error and need to replace foo above with you unique name! To exit press :q! in sequence and try again.
You need to scroll down and find the line that begins LogFile="…. and replace it
Vi has a FIND function which is to just press the / key and enter your search string i.e. LogFile= and press [ENTER]. This will take you to the first entry that has this line. To FIND AGAIN just press / followed by [ENTER] again. When you have found your line you need to INSERT. This is done by pressing the I on the keyboard. You will see the work INSERT comes up at the bottom. Use the keyboard arrows to move where you want to go and then modify the line to read.
[Did you know that / can be used in the FireFox browser for FIND also?]
To get out of INSERT mode press the [Esc] key. If you make a complete hash of it you can exit without saving with the three key sequence after pressing [Esc] :q! and try again.
Ensure the following other lines read as follows
# Substitute foo above with your unique name that you gave your awstats configuration file and don’t bother to add this line.
To save the configuration file we must now use the save command w (for Write) so press [Esc] followed by :wq!
Now go to your site with a browser and type this lot in
changing foo for your appropriate settings as required.
You should see the webpage come up but with blank stats. You will see an update Update now link at the top of the page which will then manually go and collect the stats. This bit can be automated with the use of the system cron command. This is well documented on the www.awstats.org site so you should get that bit from there.
As always with these tutorials, use at your own risk, make a backup first, subject to change without notice and probably will cause you some wasted hours. Your cat may also leave home.