AWStats on Ubuntu Server with Apache2

AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages. It uses a partial information file to be able to process large log files, often and quickly. It can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C log format) and a lot of other web, proxy, wap, streaming servers, mail servers and some ftp servers.

The following documentation contains specific information on installing and configuring Awstats with Ubuntu and Apache2. It assumes you already have an Apache2 web server up and running. For more help, get XChat and subscribe to channel “#awstats” on the Ubuntu Server.

Installation

Install AWStats with Synaptic or

sudo apt-get install awstats

Configuration

Awstats configuration files in Ubuntu are located in /etc/awstats. The template is called “awstats.conf”.

Create a copy of awstats.conf for each domain:

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

modify the file:
Open file with vi or nano:

sudo vi /etc/awstats/awstats.yourdomain.ext.conf

or

sudo nano /etc/awstats/awstats.yourdomain.ext.conf

make the following changes:

LogFile=”/var/log/apache2/access.log”

SiteDomain=”yourdomain.ext”

HostAliases=”localhost 127.0.0.1 yourdomain.ext”

generate the initial stats for AWStats based on existing var/log/apache2/access.log:

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

Apache2 Configuration

First tell your apache to use mod_cgi if you haven’t enabled it yet

sudo a2enmod cgi

In order to access Awstats, we have to tell Apache2 where it is.

tell Apache where the stats are:
Navigate to /etc/apache2/sites-available/

cd /etc/apache2/sites-available/

If you have no VirtualHosts set up, place the following code in ‘/etc/apache2/sites-available/default’. Otherwise, add this code inside the VirtualHost 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 /awstats/ /usr/lib/cgi-bin/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Reload apache2:

sudo service apache2 reload

Statistics for yourdomain.ext should now be available at:

http://yourdomain.ext/awstats/awstats.pl

and:

http://yourdomain.ext/awstats/awstats.pl?config=yourdomain.ext

for if you have multiple config files. Note that these statistics are public unless you secure them.

Crontab Configuration

Add the following code to /etc/crontab for each domain:

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

Source: Ubuntu Documentation

JAWStats Website Statistics

JAWStats is a free, open-source website statistics and analytics package. It runs in conjunction with AWStats and produces clear and informative charts, graphs and tables about your website visitors. This sofware requires AWStats to be installed. Please make sure AWStats is already installed and working on your server. JAWStats will not function without it.

Installation

Step #1

Download and unpack the latest version of JAWStats into a folder on your web server. This folder should be needs to be web-visible, i.e. you can access it from a web browser by typing in the appropriate URL.

Step #2

Duplicate the config.dist.php file, calling the new copy config.php.

Step #3

Edit your new config.php using your favourite text editor as follows:

$sDefaultLanguage: (NEW to v0.7) the default language (see list of languages below)

$sConfigDefaultView: ignore (this will be discussed in future documentation)

If you want to remove the “change site” link, change $bConfigChangeSites to false.

If you don’t want your users to be able to update stats themselves, set $bConfigUpdateSites to false (they will still need a password to do this).

$sUpdateSiteFilename: ignore (this will be discussed in future documentation)

The AWStats system already running on your server will have one or more configuration(s) in place in order for it to work properly. JAWStats needs to know the name given to these configurations. The AWStats installation guide has an example configuration called awstats.mysite.conf. For the purpose if this guide, we will use the same.

For each site you want to display stats for, edit (or create) a site configuraion array. This is a block of code in your config.php file that looks like this (you need to edit the bits shown in red):

$aConfig[“localhost”] = array(

“statspath”   => “/var/lib/awstats/“,

“updatepath” => “/usr/lib/cgi-bin/awstats.pl/”,

“siteurl” => “http://localhost”,

“sitename” => “localhost”,

“theme” => “default”,

“fadespeed” => 250,

“password” => “my-1st-password”,

“includes” => “”,

“language” => “en-gb”

);

Those variables explained:

Change the name of the array to the name of the AWStats configuration you use, eg. $aConfig[“mysite”].

“statspath”: this is a fixed or relative path to the folder on your webserver where AWStats stores the data files it generates. The files look something like awstats112007.mysite.txt. Include the trailing slash.

“updatepath”: this is a fixed or relative path to the folder on your webserver where awstats.pl is installed. Include the trailing slash.

“siteurl”: the URL of the website in question, e.g. http://www.mysite.com.

“sitename”: (NEW to v0.7) [optional] an alternative name given to the domain as opposed to displaying the actual URL

“theme”: ignore (this will be discussed in future documentation)

“fadespeed”: ignore (this will be discussed in future documentation)

“password”: the password required to dynamically update your website statistics.

“includes”: a comma seperated list of your own files you wish to include as JAWStats loads. For example, let’s say you use a cookie to control a password-protected area of your website (e.g. in a CMS) and have a piece of code at the top of each page to check the visitor is logged in before displaying the page. Well, you can include that code here. Paths, as usual, can be absolute or relative. e.g. “../check_cookie.php”

“language”: (NEW to v0.7) [optional] the default language for this site (see list of languages below)

Handling non-standard AWStats filenames

By default, AWStats produces data files in the format awstatsMMYYYY.example.com.txt where MM and DDDD represent the month and year numbers respectively and example.com would be replaced with the name of your domain config.

As of a patched release of version 0.7, JAWStats can now also handle these files. To do so, add in an extra variable to each config array that needs it called statsname. For example, this may look like:

$aConfig[“site1”] = array(

“statspath” => “/path/to/data/”,

“statsname” => “myformat[YYYY][MM].txt”,

“updatepath” => “/path/to/awstats.pl/”,

“siteurl” => “http://www.my-1st-domain.com”,

“sitename” => “My 1st Domain”,

“theme” => “default”,

“fadespeed” => 250,

“password” => “my-1st-password”,

“includes” => “”,

“language” => “en-gb”

);

The segments of the string in square brackets denote the year and month numbers, simply rearrange the string to suits your particular configuration. Date options are:

[YYYY]: Year in 4 digits, e.g. 2009

[YY]: Year in 2 digits, e.g. 09

[MM]: Month in 2 digits, e.g. 01..12

[M]: Month without leading zero, e.g. 1..12

Note: Don’t forget to include the square brackets.

Installing Language packs

Download the latest language pack from the Add-Ons section. Unzip this file into your jawstats/language directory. These translations are available to use immediately (though you may need to clear your browser cache if they don’t appear immediately).

At the time of writing available languages are:

English (use code: en-gb)

French (use code: fr)

German (use code: de-de)

Japanese (use code: jp)

Polish (use code: pl)

Swedish (use code: sv)