AWStats with lighttpd on Ubuntu

Posted by Alpha Mon, 03 Dec 2007 01:23:00 GMT

Throughout this post, I’ll use foobar as a fake domain. You should replace this with the appropriate domain(s) for your own use.

First, install AWStats.

$ sudo apt-get install awstats

/etc/lighttpd.conf will need to be modified; this will be slightly different if you want to use a directory instead of a subdomain to check your stats.

/etc/lighttpd/lighttpd.conf

server.modules += ( "mod_cgi" )

$HTTP["host"] =~ "stats.foobar" {
  alias.url = ( "/icon/" => "/usr/share/awstats/icon/",
                "/css/" => "/usr/share/doc/awstats/examples/css/",
                "/cgi-bin/" => "/usr/lib/cgi-bin/" )
  cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl" )
}

Make sure this works by visiting http://stats.foobar/cgi-bin/awstats.pl. You should get an error message from the AWStats CGI file.

In /etc/awstats, make a awstats.foobar.conf file, replacing foobar with whatever is appropriate for your purposes.

/etc/awstats/awstats.foobar.conf

LogFile="/var/log/lighttpd/access.log"
LogType=W
LogFormat=1
SiteDomain="foobar"
HostAliases="localhost 127.0.0.1 REGEX[foobar$]"
DNSLookup=1
DirData="/var/lib/awstats"
DirCgi="/cgi-bin"
DirIcons="/icon"
SkipHosts="127.0.0.1 localhost REGEX[^192\.168\.]"

Run awstats.pl to initialize the statistics database.

$ sudo -u www-data /usr/lib/cgi-bin/awstats.pl -config=foobar -update

Your stats should now be visible at http://stats.foobar/cgi-bin/awstats.pl?config=foobar.

Now all that’s left is editing the crontab and logrotate configuration files to automatically populate the stats.

/etc/cron.d/awstats

0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.foobar.conf -a -r /var/log/lighttpd/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=foobar -update >/dev/null

/etc/logrotate.d/lighttpd

prerotate
  /usr/lib/cgi-bin/awstats.pl -config=foobar -update
endscript

Posted in ,  | 4 comments | 2 trackbacks

Comments

  1. mathias said 2 days later:

    thanks for the great article. I just followed you directions and it’s working perfectly.

  2. DarkSage said 3 months later:

    Thanks for this article. I have made just one modification in the config file :

    LogFormat=”%host %virtualname – %time1 %methodurl %code %bytesd %refererquot %uaquot”

    Because I have two domains and with LogFormat=1, Awstat doesn’t make the difference between my domains.

  3. Gustavo said 8 months later:

    It’s not necessary to add the following lines to lighttpd.conf:

    server.modules += ( "mod_cgi" ) cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl" )

    Just run the command below instead: sudo lighty-enable-mod cgi

  4. mmo said 10 months later:

    Thanks for the tips

Trackbacks

Use the following link to trackback from your own site:
http://blog.kejadlen.net/trackbacks?article_id=awstats-with-lighttpd-on-ubuntu&day=02&month=12&year=2007

  1. From Sit N Go Journal
    Sit N Go
    Really enjoyed that article,tell me do you have any other blogs? Why not come and write for me I have a wicked article site you could submit article for?
  2. From myflowjob
    lighttpd mit AWStats unter Ubuntu 7.10
    Throughout this post, I’ll use foobar as a fake domain. You should replace this with the appropriate domain(s) for your own use. First, install AWStats. $ sudo apt-get install awstats /etc/lighttpd.conf will need to be modified; this will be sli...

(leave url/email »)

   Comment Markup Help Preview comment