Installing and Configuring AWStats on Linux

AWStats is short for Advanced Web Statistics. It is powerful log analyzer which creates advanced web, ftp, mail and streaming server statistics reports from server logs in graphical and easy to read formats. AWStats is a free software distributed under the GNU General Public License. It works from the command line as well as a CGI.

AWStats Requirements

- Perl 5.0.2 or above
- Server must log files in a log file you can read
- System must be able to run perl scripts

Downloading AWStats

AWStats can be downloaded from http://awstats.sourceforge.net/#DOWNLOAD. Get the last stable version. At the time of this writing, the last stable version is:

awstats-6.7.tar.gz

It is a good idea to all your downloads in one place. Download awstats to your download folder.

$ cd /usr/local/src/
$ wget http://prdownloads.sourceforge.net/awstats/awstats-6.7.tar.gz

Installing AWStats

You need root access to install awstats. Unzip the downloaded file.

$ tar -xzvf awstats-6.7.tar.gz

AWStats recommends installing the software at /usr/local/awstats, although you can install it anywhere you desire. Many choose to install it at web root but I prefer the default configuration.

$ mkdir /usr/local/awstats
$ mv awstats-6.7/* /usr/local/awstats

I recommend that you create a README.TXT file inside awstats-6.7 and log all the details as you install the software. For example:

1. awstats installed at /usr/local/awstats as recommended by awstats
2. awstats variable stored at /var/lib/awstats
3. ...

This would help you avoid frustration in the future.

AWStats edits Apache httpd config file so it is a good idea to back up this file before going further. While you are at it, why not back up all httpd config files.

$ locate httpd.conf
$ cp /etc/httpd/conf/httpd.conf /home/user/backup/apache
$ cp -r /etc/httpd/conf.d/*.conf /home/user/backup/apache

Configuring AWStats using awstats_configure.pl

AWStats comes with a configuration script, awstats_configure.pl, which configures awstats automatically. Depending on the configuration of your server, the script may or may not get the job done. Therefore, both automatic and manual configuration are covered here. Before running this script, note the address of your httpd.conf file.

$ locate httpd.conf
Note this address
$ mkdir /etc/awstats
The awstats.mole.conf file would be stored here.
$ perl /usr/local/awstats/tools/awstats_configure.pl
> /etc/httpd/conf/httpd.conf
> y
> mole  (name of your site instead of mole)
> [enter]
note the cron message before hitting enter to finish
The following if you are following my configuration
/usr/local/awstats/tools/awstats_updateall.pl now
/perl awstats.pl -update -config-mole
http://localhost/awstats/awstats.pl?config=mole

If awstats_configure.pl is successful, it would restart Apache. If it doesn't, start by checking your SeLinux log if you have SeLinux installed and active.

$ locate audit.log
$ tail /var/log/audit/audit.log

Configuring AWStats Manually

If you don't have SeLinux and the script did not succeed, you would have to configure the awstats manually.

Edit the httpd.conf

  1. search for awstats in the file and comment out all instances with # sign
  2. Change CustomLog from common to combined. Note the log file address. This would be needed later. Something like logs/access_log.
  3. Search for the comment 'Load config files'. Under this comment add Include conf.d/*.conf. This includes external configuration files. Its a cleaner way of managing your configurations.
  4. At /etc/httpd/conf.d, create a file called awstats.conf. Add the following code to it.
    Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
    Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
    Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
    ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
    #
    # To permit URL access to files in awstats folder
    #
    <Directory "/usr/local/awstats/wwwroot/">
    Options Name
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>
    

  5. Create a directory /var/lib/awstats and make it writable
  6. Edit /etc/awstats/awstats.mole.conf file. Set your log file to /var/log/httpd/access_log
  7. restart apache
    $ /sbin/service httpd restart
    

  8. In your browser type http://localhost/awstats/awstats.pl?config=mole. You should see your web statistics page.
  9. To update stats,
    $ /usr/local/awstats/tools/awstats_updateall.pl now
    

  10. If you don't see your icons, copy the icons folder to your web root. If you are using SeLinux:.
    $ ls -RZ icon/
    If you don't see something like httpd_sys_content_t, do the following:
    $ chcon -R -t httpd_sys_content_t icon
    

    If you are using SeLinux and the installation did not work. Restart from the beginning and check your SeLinux audit.log after each step.