Yesterday I finalized moving my websites to my new Linode. With all the base configuration done, it is time to start installing some monitoring and stats tools. AWStats in particular is one of my favorite tools for analyzing web traffic.

 

This guide assumes you are using Apache2, Ubuntu 10.04(though I would assume to process would be similar for Ubuntu 9.xx), and have root access to your box. Also I assume you have Apache properly setup with a working access.log file.

 

Ubuntu 10.04 has AWStats available in their repositories:

apt-get install awstats

The Ubuntu Repo. does not have the newest version of AWStats. The repo has 6.9 while the newest, stable, version is 6.95. The 6.9 install that Ubuntu provides should be enough for most people. If you wish, you can install the newest version manually and continue following afterwards.

 

AWStats does offer some sort of automated configuration process. I have never used or tested this function. If you are not comfortable with manual configuration you may want to look up the automated configuration option.

I have multiple domains I wish to track. I needed to make a copy of the default awstats.conffile for each domain. I used the format awstats.mydomain.ext.conf for my configuration file name. In my case, mydomain.ext is kastang.com. You will have to create a copy ofawstats.conf for each domain you want to monitor.

cp /etc/awstats/awstats.conf /etc/awstats/awstats.yourdomain.ext.conf

Open awstats.yourdomain.ext.conf, find and modify the following fields:

#Path to access.log for your domain
LogFile="/var/log/apache2/access.log" 

#I recommend '1' for more detailed information LogFormat=1

SiteDomain="yourdomain.ext"

HostAliases="localhost 127.0.0.1 yourdomain.ext" Now we can generate the initial stats for AWStats based off of your existing access.log file. You need to run this command for every domain you have configured.

/usr/lib/cgi-bin/awstats.pl -config=yourdomain.ext -update

Check the output for any errors. If it successfully Finds/Parses your access.log file you should be good to continue. If you have any errors, double check your configuration file and make sure the path to the access.log is correct.

 

After configuring AWStats, we need to tell Apache where to point when the AWStats address is accessed.

Navigate to /etc/apache2/sites-available/. If you have no VirtualHosts setup, you will want to place the following code in 'default'. If you have VirtualHosts setup, add this code inside theVirtualHost tag for each domain you want to monitor.

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

Reload the Apache configuration:

/etc/init.d/apache2 reload

Check to make sure you do not have and errors or warnings. Depending how you originally setup your Apache config, the /cgi-bin/ ScriptAlias may already be implemented. In this case, just remove that line from the configuration file. (Don't forget to reload the configuration after all changes).

You should now be able to navigate to http://yourdomain.ext/awstats/awstats.pl and see the existing webstats from your access.log file.

 

AWStats will not automatically update by default. I cuggest using Cron to automate the process:

Add this to crontab and it will update stats once every three hours. You can adjust the timing to suit your needs. I have seen AWStats update on a weekly basis, daily basis, and even sometimes every couple minutes. You will need to add a separate crontab line for each domain AWStat is monitoring.

0 */3 * * * root /usr/lib/cgi-bin/awstats.pl -config=yourdomain.ext -update >/dev/null

 

If you are at this step, you should have a working AWStats. One issue is AWStats does not come secured by default. They do offer to enable Authentication in the configuration, but I think it is just easier to generate a simple .htaccess file. This method is a quick and dirty method for securing AWStats. If you require a more sophisticated method of securing AWStats, please consult the official documentation.

Navigate to /usr/lib/cgi-bin/ this is where awstats.pl is located.

Create a new .htpasswd file:

htpasswd -cb /path/to/.htpasswd username password

Create a new .htaccess file with the following inside:

AuthName "AWStats Authentication"
AuthType Basic
AuthUserFile /path/to/.htpasswd
Require valid-user

Now if all goes well, when you refresh your browser you will be prompted to enter a username and password to access AWStats.

This should get you to a point where AWStats is usable and (reasonably) secure. From here you can add Plugins or further configure AWStats to fit your individual needs.

Recent Posts