Install Latest AWStats on Ubuntu Server

The AWStats package in Ubuntu (as of 14.10, and Ubuntu Vivid as of Jan 2015) repository remains at version 7.2, which dates back to July 2013. The internet has changed a lot since then and using old version only results in inaccuracies. Here is how to install the latest awstats (as of now, it is 7.4) manually.

Update in Dec 2015: updated URL to AWStats 7.4.1.

Get the RPM Package

Go to AWStats website (http://www.awstats.org/), in the “Download” section, grab the RPM file of the “last stable” release. In our case it is “awstats-7.4-1.noarch.rpm“.

Install RPM Package

We need to convert the .rpm file to a .deb file so as to use it in Debian/Ubuntu. According to Ubuntu Help, we need to use a package called alien.

sudo apt-get -y install alien  
sudo alien -i awstats-7.4-1.noarch.rpm  

By default AWStats will be installed at /usr/local/awstats

Then you can run

/usr/local/awstats/tools/awstats_configure.pl

to set up the program if it doesn’t run automatically.

Configure AWStats

If your web server is Apache, then the configure script should be able to set it up automatically. However, I run Nginx and thus more work needs doing manually.

Here is a guide for setting up AWStats with Nginx. Bear in mind that we now have different paths for the AWStats files. For example, the following paths

/usr/share/awstats/tools

should be now

/usr/local/awstats/tools

and the web interface paths like

/usr/share/awstats/icon

should be now

/usr/local/awstats/wwwroot/icon/

In the Nginx rule for forwarding cgi-bin, the parameter X_SCRIPT_FILENAME should also be changed because awstats.pl  is not at /usr/lib/cgi-bin/awstats.pl but instead /usr/local/awstats/wwwroot/cgi-bin/awstats.pl. With PHP5-FPM, the block should look like the following:

location ~ ^/cgi-bin/.*\\.(cgi|pl|py|rb) {  
    gzip off;
    include fastcgi_params; 
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index cgi-bin.php;
    fastcgi_param SCRIPT_FILENAME /etc/nginx/cgi-bin.php;
    fastcgi_param SCRIPT_NAME /cgi-bin/cgi-bin.php;
    fastcgi_param X_SCRIPT_FILENAME /usr/local/awstats/wwwroot$fastcgi_script_name;
    fastcgi_param X_SCRIPT_NAME $fastcgi_script_name; 
    fastcgi_param REMOTE_USER $remote_user;
}

Note that the Ubuntu package awstats ships some shell scripts that the RPM package doesn’t have. You need to fix it by changing those paths to the Perl scripts directly. The file correspondence should be easy to guess from the file names. For example, buildstatic.sh should be awstats_buildstaticpages.pl. There are two directories that contain Perl scripts: one is the tools dir mentioned before, and the other is /usr/local/awstats/wwwroot/cgi-bin.

Secure Web Access

Now that AWStats interface has been exposed to the Internet, you may want to add an authentication step to that page. Here is a guide to add basic HTTP authentication to Nginx.

More Tweaks

If you have previously added AWStats updateall to Nginx’s logrotate conf file, be sure to update the AWStats paths in (/etc/logrotate.d/nginx) also.

If you have crontab that runs AWStats updateall, you need to update the AWStats paths in that file (e.g., /etc/cron.d/awstats), too.

If you want to enable hostinfo plugin, for Ubuntu 14.04 the package libnet-xwhois-perl is needed.