Setting up awstats on Debian Lenny

Setting up awstats on Debian Lenny is a bit tricky. I will describe how to set up awstats and install the cron job for updating the awstats statistics automatically. The Last step will be to set up logrotate to not miss any user.

  1. What is awstats?
  2. Installing awstats
  3. Apache virtual host configuration
  4. Customize the awstats config file
  5. Update awstats automaticly via cronjob
  6. Alternative cronjob
  7. Searching for errors
  8. Customize logrotate
  9. Finished?

What is awstats?

Awstats is a web analyzer written on pearl. That means it reads the log files from ftp, mail, streaming, and web server and shows user statistics on its web front end. In the next steps I will set up awstats with apache2. This will give the possibility to see the browser, duration, the source, count of visits … of your sites user. And thats not all. You can see web crawlers visited your site witch helps you for SEO.

Installing awstats

The requirement for this tutorial is a working apache2 installation. All shell commands are executed as root. First we need to install awstats through debians package manager. I like to use aptitude for this.

aptitude install awstats

Debian saves the html files for awstats in /usr/share/doc/awstats/examples. To make the awstats config script run without errors we have to move these files and customize them a bit.

mv /usr/share/doc/awstats/examples /usr/local/awstats
mkdir -p /usr/local/awstats/wwwroot/cgi-bin/
cd /usr/local/awstats/
gunzip awstats.model.conf.gz
mv awstats.model.conf usr/local/awstats/wwwroot/cgi-bin/
cp /usr/lib/cgi-bin/awstats.pl /usr/local/awstats/wwwroot/cgi-bin/
/usr/local/awstats/awstats_configure.pl

  • On Line 1 we move the example files to /usr/local/awstats. The awstats folder will be created new.
  • On Line 2 the folder wwwroot/cgi-bin/ is created in /usr/local/awstats
  • Line 4 unzip the awstats.model.conf.gz
  • Line 5 move the awstats.model.conf to the cgi-bin folder.
  • Line 6 copies the awstats.pl to the cgi-bin dir
  • Line 7 runs the config script

script output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
./awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.7) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).

-----> Running OS detected: Linux, BSD or Unix

-----> Check for web server install

Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> none

Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)

-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.

-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y

----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> MySite.de

-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>

----->; Create config file '/etc/awstats/awstats.MySite.de.conf'
Config file /etc/awstats/awstats.MySite.de.conf created.

-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=MySite.de
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...

A SIMPLE config file has been created: /etc/awstats/awstats.MySite.de.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'MySite.de' with command:
> perl awstats.pl -update -config=MySite.de
You can also build static report pages for 'MySite.de' with command:
> perl awstats.pl -output=pagetype -config=MySite.de

Press ENTER to finish...
  • In line 24 we where asked for oure apache config files, to setup awstats. I always leave this empty because I don’t like scripts to probably destroy my old configs.
  • In line 36 we have to say YES, because we want awstats to create his config file.
  • line 43 asks for our domain. Put it in here without sub-domains. If you need sub-domains you can add it later to the config file.
  • line 49 asks where to create the config file. i always leave it at /etc/awstats

At /etc/awstats a file named awstats.YOURDOMAIN.conf was created. If you want to rerun this script for the same domain you first have to delete this file or rename it.

Apache virtual host configuration

Before we take a look at the most important lines of the awstats config file we will configure the webserver. I assume that at least one site is properly running. Don’t forget to reload the config script to your server with /etc/init.d/apache2 force-reload after every change to see the results!

We now have to add the following lines to /etc/apache2/sites-available/default or any other running vhost:

1
2
3
4
5
ScriptAlias /awstats /usr/lib/cgi-bin/
Alias /awstats-icon/ /usr/share/awstats/icon/
Options None AllowOverride None
Order allow,deny
Allow from all
  • Line 1 defines a script alias for the awstats.pl script.
  • In Line 2 defines an alias for the pictures. We’ll have to add this later to the awstats config file
  • Lines 4 – 8 are for access control

If you have a very restrictive vhost config, you have to add these lines, too. They will allow access to the awstats script.

9
10
11
12
Options None
AllowOverride None
Order allow,deny
Allow from all

Under the following address your awstats installation should be reachable:
http://YourVhost/awstats/awstats.pl?config=MySite.de

Attention: MySite.de is the name you’ve given the awstats config file in line 43 of the script.

Customize the awstats config file

If see your awstats installation the first time in your browser you will recognize that no images are displayed. This brings us to the config file /etc/awstats/:

51
 LogFile=""

Here you have to point to the web servers log file. For Apache2 it is /var/log/apache2/access.log if no other is set in your vhost file.

122
 LogFormat=1

The logformat should be 1 to see the browser an operatoin system of your visitors.

153
 SiteDomain=""

Here you should fill in the domain of your browser.

153
 HostAliases=""

This is the place to list, seperated with blanks, all domains your site can be reached(mysite.de www.mysite.de admin.mysite.de localhost).

188
 DNSLookup=2

If you set this to 2 the visitors will not only be listed as IPs.

222
 DirIcons=""

This tells the server where the icons are stored. Thanks to our apache alias we kann write set this to “/awstats-icon”.

Update awstats automaticly via cronjob

Awstats doesn’t update it’s log files automatically. You have to set up a cronjob that runs the awstats update script periodically. Write the following to /etc/crontab

1
48,18 * * * * root /usr/lib/cgi-bin/awstats.pl -config=MeineSeite.de -update >/dev/null
  • The first twp number are the minutes (0 – 59), (48,18) means every 48th and 18th minute of an houre
  • the following *s are representing hours (0 – 23), days(1 – 31) of the month Monats and month (1-12) and day of the week (0 – 6, 0 = Sunday)
  • root is the user whitch executes the task
  • /usr/lib/cgi-bin/awstats.pl -config=MySite.de -update >/dev/null is the command to update the awstats

You see we let root execute the command so for security reason its important that no other yuser has permissions to change /usr/lib/cgi-bin/awstats.pl.

ls -l /usr/lib/cgi-bin/awstats.pl
-rwxr-xr-x 1 root root 548960 10. Dez 2008 /usr/lib/cgi-bin/awstats.pl

Alternative cron job

(Maybe there have to be changed other poermissions, too)
Here a user is created with permissions to run the script. We create him with useradd so no login is available for him.

useradd awstat

Next Step is to add the user to group adm. This can be done with

useradd -G {group-name} username

or edit the /etc/group file. Just add the user name behind the adm group.

1
adm:x:4:awstat

Now you have too change root to your created user in /etc/crontab

1
48,18 * * * * awstat /usr/lib/cgi-bin/awstats.pl -config=MySite.de -update >/dev/null

Searching for errors

You can see how up to date your stats are in the upper left corner at the web front end. If the stats don’t update just set the minutes in etc/crontab to *. With this th cronjob is executed every minute. Then become your created user with

su username

and try to run the update command without >/dev/null. If root updates your awstat logs there should be no permission problems.

  • is your user allowed to execute /usr/lib/cgi-bin/awstats.pl and to read the ?
  • is the user allowed to write to /var/lib/awstats/* ?
  • is the user to write to /var/lib/awstats?
  • is the path to the script in /etc/crontab and to the logfiles /etc/awstats/yourlogfile right?

After you found the mistake don’t forget to to get root with exit and change the * in /etc/crontab to your settings.

Customize logrotate

Logrotate is a service that handles the log files. It moves them if they crow to big or in a defined period of time. Our statistics are updatet every 30 minutes, so if the log rotates 29 minutes after the last statistic update we lose 29 minutes of user stats.
To prevent this we have to tell logrotate to rum the awstats update script just bevore rotating the log files.
/etc/logrotate.d/apache2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/var/log/apache/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
prerotate
/usr/lib/cgi-bin/awstats.pl -config=ghaint.no-ip.org -update
endscript
postrotate
if [ -f /var/run/apache.pid ]; then \
if [ -x /usr/sbin/invoke-rc.d ]; then \
invoke-rc.d apache reload > /dev/null; \
else \
/etc/init.d/apache reload > /dev/null; \
fi; \
fi;
endscript
}

Here you have to look at the prerotate block at line 10 to 12. If theres no prerotate block in your file just add it above the postrotate block.

Finished?

Awstats is running and updates itself automatically. Now you need to enable an access control so not everybody is able to see your website stats. This can easily be done with apache.

9 thoughts on “Setting up awstats on Debian Lenny

  1. user. This means that a security vulnerability in a CGI script executed by Apache (for a dynamic page) won’t compromise the whole system, but only the files owned by this particular user.

  2. I savour, lead to I found just what I was taking
    a look for. You have ended my 4 day long hunt!
    God Bless you man. Have a great day. Bye

Leave a Reply

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


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>