Installing awstats on Ubuntu Feisty

I started to use awstats for creating the site statistics on our server. After installing the ubuntu package, there are still a few things that I had to do:

  1. Install libnet-ip-perl and libgeo-ipfree-perl in order to map the dns entries to countries.

    Download
    http://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.2.tar.gz
    http://www.maxmind.com/download/geoip/api/perl/Geo-IP-1.27.tar.gz
    http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
    http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
    http://www.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
    in order to use the free, but non-open source versions of GeoIP.

  2. Since I use vhosts, I put for every vhost one configuration file into the /etc/awstats/ directory.
  3. Into the vhost-specific configuration file I only put directives that are different from the default configuration file /etc/awstats/awstats.conf. For my own vhost (jeltsch.org) these directives are as follows:

    LogFile="/var/log/apache2/jeltsch.org/access.log"
    LogFormat=1
    DNSLookup=1
    SiteDomain="jeltsch.org"
    HostAliases="www.jeltsch.org"
    AllowToUpdateStatsFromBrowser=1
    AllowFullYearView=3
    EnableLockForUpdate=1
    AllowAccessFromWebToAuthenticatedUsersOnly=1
    AllowAccessFromWebToFollowingAuthenticatedUsers="jeltsch"
    DefaultFile="index.html index.php"
    LoadPlugin="geoipfree"

    If you want to use the non-OSS GeoIP stuff, replace the last line by the following:

    LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/perl/5.8.8/Geo/IP/GeoIP.dat"
    LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/perl/5.8.8/Geo/IP/GeoLiteCity.dat"
    LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /usr/local/share/perl/5.8.8/Geo/IP/GeoIPASNum.dat"

    Compile the GeoIP-1.4.2 stuff according to the INSTALL file. You probably need to get some stuff first to be able to do the compilation. Execute apt-get install build-essential Compile Geo-IP-1.27 according to the INSTALL file. Unzip the 3 databases and put them into the /usr/local/share/perl/5.8.8/Geo/IP/ directory.

  4. In order to protect the statistics I limit access to authenticated users.
    The following lines has to be added to the vhost-specific apache configuration file /etc/apache2/sites-available/jeltsch.org:
    <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    AuthType basic #added line
    AuthName "cgi-bin restricted" #added line
    AuthUserFile /etc/apache2/.htpasswd #added line
    <Files awstats.pl> #added line
    Require valid-user #added line
    </Files> #added line
    </Directory>

    The you need to create the /etc/apache2/.htpasswd file and add a user password with the command:

    htpasswd -c /etc/apache2/.htpasswd username

  5. Now everything works apart from the images which awstats expects to be in the icon subdirectory of the document root for the vhost. I just created a link:

    ln -s /usr/share/awstats/icon /var/www/jeltsch.org/icon

    On some Ubutu installs the log files cannot be accessed and even if you change the permissions to
    chomd -R 755 /var/log/apache2 they keep being switched back by the logrotation script. In order to fix that read this post.