nav HOME » System administration » How-to: AWstats installation and configuration on Debian

How-to: AWstats installation and configuration on Debian

This is a simple tutorial on how to install AWstats on Debian and configure it for displaying web statistics. I’ve tried this on lenny, but it should also work on other versions with small or no modifications.

First, make sure your web server is configured to write access logs to combined format. This is default behavior for nginx and lighttpd servers, but not for apache. To tell apache to use combined format, use something like this:

CustomLog logs/access_log combined

Install awstats package:

apt-get install awstats

Create a config file for our new domain:

cp /etc/awstats/awstats.conf /etc/awstats/awstats.www.example.com.conf

Edit this lines in new configuration file:

LogFile="/var/log/nginx/access.www.example.com.log"
LogFormat=1
SiteDomain="www.example.com"
DNSLookup=0
DirData="/var/lib/awstats/www.example.com/"
HostAliases="example.com"

Create a database directory:

mkdir /var/lib/awstats/www.example.com/

OK, configuration is now done, we can create some stats… simplest way is by using awstats.pl:

/usr/lib/cgi-bin/awstats.pl -config=www.example.com -update -output > /www/sites/www.example.com/awstats.html

But, this will only create main reports. To create all reports, you can use awstats_buildstaticpages.

It’s a good idea to save this command into a script file (e.g. /data/bin/awstats/awstats_update_example) which can be easily called when we need to update stats.

/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl -update -config=www.example.com -dir=/www/sites/webstats.example.com/ -awstatsprog=/usr/lib/cgi-bin/awstats.pl > /dev/null

Updating can be done from cron, but that can result in lost data, because of log rotation. Best option is to call update script just before logs are rotated. Nginx logs are, by default, rotated daily, so we can just insert our script in nginx logrotate configuration file (/etc/logrotate.d/nginx):

/var/log/nginx/*.log {
    daily
    ...
    sharedscripts
    prerotate
        /data/bin/awstats/awstats_update_example
    endscript
    ...
}

You can try to run logrotate manually with:

logrotate -vf /etc/logrotate.conf

OK, now we just need to make html files available from web.

I will post configuration for nginx, but that can be easily adapted for other web servers.

This is an example of virtual host file (e.g. /etc/nginx/sites-enabled/webstats.example.com):

server {
    listen 80;
    server_name  webstats.example.com;

    location / {
        root   /www/sites/webstats.example.com/;
        index  awstats.www.example.com.html;
    }    

    location  /awstats-icon/ {
        alias  /usr/share/awstats/icon/;
    }    

    auth_basic            "Restricted";
    auth_basic_user_file  /etc/awstats/webstats.example.com.htpasswd;

    access_log /var/log/nginx/access.webstats.example.com.log;
    error_log /var/log/nginx/error.webstats.example.com.log;
}

Create a password file:

htpasswd -c /etc/awstats/webstats.example.com.htpasswd master

Reload nginx configuration:

/etc/init.d/nginx reload

And we’re done.

AWstats beside this static pages also supports dynamic CGI reports, but that is slower and less secure, so unless you don’t really need that, static pages will do just fine.

CustomLog logs/access_log combined

Posted in System administration
Tags: , , , , , ,

6 Responses to “How-to: AWstats installation and configuration on Debian”

  1. Bob says:

    Please explain in more detail the meaning of grey section 7. (the one that begins with /usr/share/doc/awstats/examples/awstats_buildstaticpages.pl)

    I can do everything up till there and it works ok (except that awstats reports no search engine bots and I can see from the access log that googlebot has been crawling like crazy)

    but when I get to that one, I try to convert it to my directory and site structure but it just errors out. I dont understand what that line is trying to do, so I do not know where to begin.

    I have my domain set up in “/usr/share/nginx/sites-enabled/mydomain.com (no www)
    This allows me to add subdomains at will. The log file is of all subdomains and I have no problem with that as it is my overall stats that I am interested in.

    However I am stalled at section 7 and would appreciate any help you can offer.

  2. nix says:

    awstats_buildstaticpages.pl just calls awstats.pl for every possible -output option and dumps result into directory specified by -dir option.
    What kind of error you get when you run that command?

  3. Bob says:

    I type in /usr/share/doc/awstats/examples/awstats_buildstaticpages.pl -update -config=mydomain.com -dir=/usr/share/nginx/sites-enabled/mydomain.com/webstats.html -awstatsprog=/usr/lib/cgi-bin/awstats.pl > /dev/null

    and it returns

    Error: Couldn’t open log file “/usr/share/nginx/sites-enabled/mydomain.com/webstats.html/awstats.mydomain.com.html” for writing : No such file or directory.

    I do not understand why it is writing .html at the end of the domain name.

    I am a bit of a linux newb, coming from control panels to nginx has been a tough but rewarding experience.

  4. nix says:

    I see, you’re passing file path to -dir option… that doesn’t work beacuse it expects directory in which will create reports…
    Just create new folder, e.g. /usr/share/nginx/sites-enabled/mydomain.com/webstats/ and pass that as -dir option…

  5. Well I truly liked studying it. This information procured by you is very helpful for accurate planning.

  6. fwix says:

    thanks for this usefull howto.

    I suggest that you change the command to produce awstats report, giving the full path for the -config argument :
    /usr/lib/cgi-bin/awstats.pl -config=/etc/awstats/awstats.mydomain.conf -update -output > /var/www/mydomain/awstats/index.html

    On my Debian, the full path is needed.

    :)

Leave a Reply