Setting Up AWStats with Lighttpd and Debian

After installing AWStats via apt-get, I realised that its install doesn’t really play very nicely with Lighttpd. That is, the auto_setup file wouldn’t work. Or at least I don’t think it will. I wasted a lot of time if it actually does work! And also, its files and folders seemed spread around everywhere, and they weren’t in the location that all the tutorials and how-tos said they were going to be.

In the end, I opted to install the RPM (which installed them into standard locations) by turning it into a deb file using Alien. It was simple enough.


Pop over here and copy the link to the latest RPM download. Now:

sudo apt-get install alien
wget <link>
sudo alien -d <filename>.rpm
sudo dpkg -i <filename>.deb

Lighttpd Configuration

Now everything should be installed into /usr/local/awstats. Edit your lighttpd.conf to include the necessary paths:

# Aliases for AWStats
alias.url += (
                "/awstatsclasses" => "/usr/local/awstats/wwwroot/classes/",
                "/awstatscss" => "/usr/local/awstats/wwwroot/css/",
                "/awstatsicons" => "/usr/local/awstats/wwwroot/icon/",
                "/awstats" => "/usr/local/awstats/wwwroot/cgi-bin/",
                "/icon/" => "/usr/local/awstats/wwwroot/icon/"

You’ll want to change the “+=” to simply “=” if this is the first or only alias.url entry in your conf file. If you do not, when you restart Lighttpd it will spit an error out at you.

Also add this to provide AWStats cgi-bin access:

# provide awstats cgi-bin access
$HTTP["url"] =~ "/awstats/" {
      cgi.assign = ( ".pl" => "/usr/bin/perl" )

Now restart Lighttpd with something like sudo /etc/init.d/lighttpd restart

AWStats Configuration

Next we’ve got to configure AWStats just the way we want it. There’s a model/example configuration file included with AWStats, it’s found in /etc/awstats:

sudo cp awstats.model.conf awstats.<nameofyourdomain>.<tld>.conf

For example, I did:

sudo cp awstats.model.conf

You can make as many copies of this conf as you like if you have more than one domain tied to a specific server, simply name them all correctly and repeat the process below.

sudo $EDITOR /etc/awstats/awstats.<nameofyourdomain>.<tld>.conf

Make sure you change at least the following values to your own:


LogFile tells AWStats where to look for your domain’s log. For instance, yours may be /var/log/lighttpd/access.log – you can always grep your lighttpd.conf file for accesslog.filename to be sure of it. If you’re using WordPress, you may have your logs in /var/www/<sitename>/logs/access.log. Again searching for accesslog.filename will tell you.

SiteDomain is pretty self-explanatory. Your site’s domain name. My entry here is simply “”.

DirData is the path where you’d like data generated by AWStats to be kept. Make sure whichever directory you pick is writable by the user that you webserver (lighttpd) runs under:

sudo chown -R www-data:www-data /path/to/folder/

Make sure that LogFormat is set as 1. This is the correct setting for Apache and Lighttpd logs.

The next couple are optional:


They default to 2 and 2 respectively. I prefer setting them to the values above as DNSLookup shows names instead of IP addresses and basic country reports, and AllowFullYearView allows a full year of stats to be viewed on your browser.

You can also uncomment a few plugins for extra functionality. I like “tooltips”, “graphgooglechartapi”, “geoipfree” and “hostinfo”. The last two do require you to install a couple of Perl modules though, namely Geo::IPfree and Net::XWhois.


Finally, simply update your databases!

sudo /usr/local/awstats/wwwroot/cgi-bin/ -update -config=<domain>.<tld>

For example, I did:

sudo /usr/local/awstats/wwwroot/cgi-bin/ -update

You can now view your shiny new, comprehensive stats at http://yourserver.tld/awstats/<domain>.<tld>


Now, we don’t want to be running this command all the time. Let’s add it to cron:

sudo $EDITOR /etc/cron.daily/01awstats

Paste in the following and save:

# path to cgi-bin
# append your domain
DOMAINS="<domain1>.<tld> <domain2>.<tld> <domain3>.<tld>"
# loop through all domains
for d in ${DOMAINS}
   ${AWS} -update -config=${d}

Now chmod the file to make it executable:

sudo chmod +x /etc/cron.daily/01awstats


The very last thing you might want to do (honestly, I promise) is add a domain name selection page. This is handy if you have more than domain. If you want one, create an index.html in /usr/local/awstats/wwwroot/cgi-bin/:

sudo $EDITOR /usr/local/awstats/wwwroot/cgi-bin/index.html

Paste in and adapt the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function usePage(frm,nm){
for (var i_tem = 0, bobs=frm.elements; i_tem < bobs.length; i_tem++)
Which site would you like to see stats for?
<form action="#" method="post" onsubmit="usePage(this, 'bob');">
<br><input type="radio" name="bob" value=""> name1<br>
<input type="radio" name="bob" value=""> name2<br>
<input type="radio" name="bob" value=""> name3<br><br>
<input type="submit" value="Go!">

Add in or remove as many <input type="radio" name="bob" value=""> namex<br> lines as you need. Simply browse to http://yourserver.tld/awstats to pick and explore your domain.

Here’s a preview of those radio buttons:

Screen shot 2011-07-19 at 03.26.21

Leave a Reply

Your email address will not be published. Required fields are marked *