KB: AWStats on Ubuntu

Installation and configuration guide for AWStats on Ubuntu Linux.

Contents

Installation and Configuration

1. Install AWStats:

apt-get install awstats

2. Create and edit /etc/apache2/awstats.conf:


Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/

Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

3. Edit /etc/apache2/apache2.conf adding the following at the end of the file:

Include /etc/apache2/awstats.conf

4. Reload apache2:

/etc/init.d/apache2 reload

5. Copy /etc/awstats/awstats.conf as follows (this example is for my www virtual host):

cp /etc/awstats/awstats.conf /etc/awstats/awstats.www.conf

6. Edit the above file (/etc/awstats/awstats.www.conf) and modify the following lines to suit your needs:

Web log:


LogFile="/var/log/apache2/www.access.log"
#LogFile="/usr/share/doc/awstats/examples/logresolvemerge.pl /var/log/apache2/www*.gz |"  LogType=M

LogFormat=1

SiteDomain="zunisoft.com"

ShowBrowsersStats=1
ShowOSStats=1

Mail log (Postfix):


LogFile="perl /usr/share/doc/awstats/examples/maillogconvert.pl standard < /var/log/mail.log |"

LogType=M
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd" SiteDomain="mail.zunisoft.com"

LevelForBrowsersDetection=0
LevelForOSDetection=0
LevelForRefererAnalyze=0
LevelForRobotsDetection=0
LevelForWormsDetection=0
LevelForSearchEnginesDetection=0
LevelForFileTypesDetection=0

ShowMenu=1
ShowSummary=HB
ShowMonthStats=HB
ShowDaysOfMonthStats=HB
ShowDaysOfWeekStats=HB
ShowHoursStats=HB
ShowDomainsStats=0
ShowHostsStats=HBL
ShowAuthenticatedUsers=0
ShowRobotsStats=0
ShowEMailSenders=HBML
ShowEMailReceivers=HBML
ShowSessionsStats=0
ShowPagesStats=0
ShowFileTypesStats=0
ShowFileSizesStats=0
ShowBrowsersStats=0
ShowOSStats=0
ShowOriginStats=0
ShowKeyphrasesStats=0
ShowKeywordsStats=0
ShowMiscStats=0
ShowHTTPErrorsStats=0
ShowSMTPErrorsStats=1

7. Generate statistics by running the following (change the -config parameter for each awstats.conf file you created):

/usr/lib/cgi-bin/awstats.pl -update -config=www

8. Navigate to http://www.mysite.org/awstats/awstats.pl?config=www to view the results.

Auto Statistics Generation

1. Edit /etc/cron.d/awstats adding an entry for each awstats.conf file you created:


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

Secure Access to AWStats

1. Create a http user and password using htpasswd (follow the prompts):

htpasswd -c /etc/apache2/passwd user1

or

htpasswd /etc/apache2/passwd user2

Note: the htpasswd -c switch creates the password file, if you attempt to add another user later using the -c switch, your existing file will be overwritten.

2. Edit your virtual host file and add the following to restrict access to your awstats installation:


<location awstats>
    SetHandler cgi-script
    Order deny,allow
    Deny from all
    AuthName "Web Statistics Login"
    AuthType basic
    AuthUserFile /etc/apache2/passwd
    Require valid-user
    Satisfy any
</location>

To Top

Please follow and like us:

Leave a Reply

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