
AWStats is a log analyzer application written in Perl, that summarizes valuable information about the traffic received by a web server, and displays it in a web frontend with data in tables and graphs.
This post explains how to install and configure AWStats in an apache web server running on a linux (Debian) machine. The official documentation of AWStats is available at http://awstats.sourceforge.net/docs/
AWStats versus Google Analytics
AWStats generates statistics about visitors, visits, pageviews, and detailed reports by type of browser, country, etc… much like Google Analytics does. The difference resides in the fact that AWStats does not require adding javascript to the pages, and therefore is able to anlyze all kind of traffic, even traffic generated from browsers with no javascript support (including many crawlers that can generate a significative load on our server).
AWStats installation
We start by downloading from the AWStats home page at sourceforge the ‘awstats-7.0.zip’ package.
We must uncompress the zip file under ‘/usr/local’, and rename the resulting ‘awstats-7.0’ directory as ‘awstats’. Next, we run the ‘awstats_configure.pl’ configuration script under the ‘awstats/tools’ subdirectory.
1 2 3 4 5 6 7 |
$ cd /usr/local $ unzip awstats-7.0.zip $ mv awstats-7.0 awstats $ cd awstats/tools $ sudo perl awstats_configure.pl |
The complete log of the initial configuration is as follows:
1. The script requests the location of the web server configuration file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
$ sudo perl awstats_configure.pl ----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur ----- This tool will help you to configure AWStats to analyze statistics for one web server. You can try to use it to let it do all that is possible in AWStats setup, however following the step by step manual setup documentation (docs/index.html) is often a better idea. Above all if: - You are not an administrator user, - You want to analyze downloaded log files without web server, - You want to analyze mail or ftp log files instead of web log files, - You need to analyze load balanced servers log files, - You want to 'understand' all possible ways to use AWStats... Read the AWStats documentation (docs/index.html). -----> Running OS detected: Linux, BSD or Unix -----> Check for web server install Enter full config file path of your Web server. Example: /etc/httpd/httpd.conf Example: /usr/local/apache2/conf/httpd.conf Example: c:Program filesapache groupapacheconfhttpd.conf Config file path ('none' to skip web server setup): > /etc/apache2/httpd.conf |
2. The apache configuration file is modified by adding the required directives to give access to the AWStats frontend:
1 2 3 4 5 6 7 8 9 10 11 12 |
-----> Check and complete web server config file '/etc/apache2/httpd.conf' Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"' Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"' Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"' Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"' Add '<Directory>' directive AWStats directives added to Apache config file. -----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' File awstats.model.conf updated. |
3. A configuration file for our main site is created.
We will see later that this script needs to be edited to match the details of our web server setup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
-----> Need to create a new config file ? Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ? y -----> Define config file name to create What is the name of your web site or profile analysis ? Example: www.mysite.com Example: demo Your web site, virtual server or profile name: > www.openalfa.com -----> Define config file path In which directory do you plan to store your config file(s) ? Default: /etc/awstats Directory path to store config file(s) (Enter for default): > -----> Create config file '/etc/awstats/awstats.www.openalfa.com.conf' Config file /etc/awstats/awstats.www.openalfa.com.conf created. -----> Restart Web server with '/etc/init.d/apache restart' |
4. The script informs us that the update process should be automated by means of a cron entry.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
-----> Add update process inside a scheduler Sorry, configure.pl does not support automatic add to cron yet. You can do it manually by adding the following command to your cron: /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.openalfa.com Or if you have several config files and prefer having only one command: /usr/local/awstats/tools/awstats_updateall.pl now Press ENTER to continue... A SIMPLE config file has been created: /etc/awstats/awstats.www.openalfa.com.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'www.openalfa.com' with command: > perl awstats.pl -update -config=www.openalfa.com You can also read your statistics for 'www.openalfa.com' with URL: > http://localhost/awstats/awstats.pl?config=www.openalfa.com Press ENTER to finish... |
Once the initial configuration is done, we must create the directory where the AWStats database will be located:
1 2 3 |
$ sudo mkdir /var/lib/awstats |
With this, we can now point our browser to ‘http://localhost/awstats/awstats.pl?config=www.openalfa.com’ , and give a first look to the AWStats frontend:
Of course, all data are zero in this first page, because we have not processed yet any log file. But we can already browse the variety of reports that AWStats will make available with a single click from this page.
Processing of log files
Processing of a log file is performed by running the script “/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.openalfa.com”. But first, we need to edit the configuration file for our site, to specify the location of the log files and how they are named.
Our server creates daily log files with filenames in the format ‘access_log.YYYY-MM-DD-00_00_00’, under ‘/var/log/apache2/openalfa’. For instance:
1 2 3 |
access_log.2012-10-01-00_00_00 |
Therefore, we must edit the ‘/etc/awstats/awstats.www.openalfa.com.conf’ configuration file, and replace the line ‘LogFile=”/var/log/httpd/mylog.log”‘ with:
1 2 3 |
LogFile="/var/log/apache2/openalfa/access_log.%YYYY-24-%MM-24-%DD-24-00_00_00" |
With this setting we ensure that, every time the update script is run, the log file to be processed will be that of the day before the day when the update script is run.
Once the configuration file has been edited, the update is performed issuing the command:
1 2 3 |
$ sudo /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.openalfa.com |
going back to the browser and reloading the awstats home page, we can confirm that the first processed data are present in it:
Finally, we just have to automate the update process to be run on a daily basis. We do this by adding a cron entry like this:
1 2 3 |
5 3 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.openalfa.com |
Processing of old log files
Most likely, by the time we perform the AWStats installation there is aready a set of old log files from the days, months and even years since the web server started. If we want to process these historical data, we must follow these steps:
1. Delete the AWStats database just created in the first run of the update:
1 2 3 |
$ rm /var/lib/awstats/* |
2. Edit the configuration file ‘/etc/awstats/awstats.www.openalfa.com.conf’ to specify the log data to be processed as:
1 2 3 |
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/apache2/openalfa/access_* |" |
The update process will read the output from the ‘logresolvemerge.pl’ script included in the AWStats package.
This script reads all the log files given as argument (in the example above, all ‘access_*’ files under the ‘/var/log/apache2/openalfa’ directory), and will send them to the update process, sorted by the dates in the log entries in them.
3. Execute the update process
1 2 3 |
$ sudo /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.openalfa.com |
4. Edit again the configuration file to revert the value of the LogFile setting:
1 2 3 |
LogFile="/var/log/apache2/openalfa/access_log.%YYYY-24-%MM-24-%DD-24-00_00_00" |
How to configure AWStats for several sites in the same web server
Our web server might be giving service to more than one site (for instance, by using ‘VirtualHost’ directives). In our case the three domains www.openalfa.com, blog.openalfa.com and blog-en.openalfa.com are served by the same web server.
The configuration of AWStats in this case is performed by creating under the ‘/etc/awstats’ directory a configuration file for each domain. Inside the configuration files, the ‘LogFile’ setting will specify the location and format of the log files for each domain.
Then, instead of creating a separate cron entry for each domain, we create a single entry to process all of them like this:
1 2 3 |
5 3 * * * /usr/local/awstats/tools/awstats_updateall.pl now |
For each of these domains, if we want to process old log files previously existing, the same considerations exposed in the previous section apply.
—