Awstats on Debian (Installation & Setup)

Home Page Moz d-a Logo Awstats-Debian DebianMac Install DVD Burning Bookmarklets. Debzilla Affair Donations

Installing awstats on Debian GNU/Linux for your apache web server is as easy as it is to install any other package using apt. Issuing the following command as super user would install the latest version of awstats available for your Debian distribution.

~$ apt-get install awstats

Run the awstats configure script to setup awstats for the domain you want to monitor. Remember to repeat the configuration process for each domain you want to monitor. On Debian, the configure script is not in the upstream location (see below for correct location). The text from the script run is provided below:

~$ cd /usr/share/doc/awstats/examples/
/usr/share/doc/awstats/examples$ perl awstats_configure.pl
----- AWStats configure 1.0 (build 1.32) (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
Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/usr/share/doc/awstats/examples
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ? y

-----> 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):
> /etc/apache/httpd.conf

-----> Check and complete web server config file '/etc/apache/httpd.conf'
Add 'Alias /awstatsclasses "/usr/share/doc/awstats/examples/wwwroot/classes/"'
Add 'Alias /awstatscss "/usr/share/doc/awstats/examples/wwwroot/css/"'
Add 'Alias /awstatsicons "/usr/share/doc/awstats/examples/wwwroot/icon/"'
Add 'ScriptAlias /awstats/ "/usr/share/doc/awstats/examples/wwwroot/cgi-bin/"'
Add '' directive
AWStats directives added to Apache config file.

-----> 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:
> full-domain-name

-----> Create config file '/etc/awstats/awstats.full-domain-name.conf'
Error: Failed to open '/usr/share/doc/awstats/examples/wwwroot/cgi-bin/awstats.model.conf' for read.

Even though the script exited with an error, I noticed that the configuration file was properly created at the desired location! After the script exits, you should set up an alias for awstats-icons in httpd.conf. Inserted it in the Aliases section. The awstats_configure.pl script adds it in the end of httpd.conf - comment that out. Your entry for /awstats-icon/ in Aliases section should look like:

Alias /awstats-icon/ /usr/share/awstats/icon/

<Directory /usr/share/awstats/icon>
  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

Restart Apache

~$ /etc/init.d/apache restart

Edit the awstats' domain configuration file you just created /etc/awstats/awstats.full-domain-name.conf to have LogFormat=1. Default "LogFormat=4" does not show Browsers, OS, keywords, etc. Make sure the parameter SiteDomain has a value of the domain to monitor (i.e. same as the string between awstats. and .conf of the filename) And then generate stats the first time by using the following command:

~$/usr/lib/cgi-bin/awstats.pl -config=full-domain-name -update

Update for config "/etc/awstats/awstats.full-domain-name.conf"
With data in log file "/var/log/apache/access.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 60
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 60 new qualified records.

Now you can check the statistics just created by visiting http://domain.name/cgi-bin/awstats.pl?config=domain.name. With everything done till here, awstats should be working for the domain you configured it for.

The next step is to automate the tast of generating the statistics. The automating setup step is basically two-part step. In first part we setup a cron job for awstats to run periodically(every 30 minutes) by editing /etc/cron.d/awstats to:

3,33 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=full-domain-name -update >/dev/null

and then we add a prerotate operation to /etc/logrotate.d/apache to run awstats.pl before every logrotate, which should be as shown below after editing.

/var/log/apache/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
prerotate
/usr/lib/cgi-bin/awstats.pl -config=full-domain-name -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
}

You will also notice the permissions for the apache log files have been changed to 644 root:adm(do a chmod o+r /var/log/apache/access.log for the already created file). This is the easiest way to let awstats acccess the apache log file. For other methods read documentation /usr/share/doc/awstats/README.Debian.

This should be all that you need to get awstats log monitoring running for your apache web server. After everything is setup and running it is a good idea to go and read all the documentation in the awstats configuration file for every option e.g. enable logging of mail server, ftp server, adding plugins, etc. You might want to tweek those options according to your personal likings. The configuration file has pretty detailed explanation just before every option. Happy Logging!