All steps as root, unless mentioned otherwise.

First of all, configure your Apache server to use “combined”, instead of “common” as log format, in /etc/httpd/conf/httpd.conf .

In Section 1:

CustomLog logs/access_log combined

In each virtual host:-

ErrorLog /var/www/vhosts/example.com/statistics/logs/error_log

CustomLog /var/www/vhosts/example.com/statistics/logs/access_log common

Download awstats in /root/ from: http://awstats.sourceforge.net/

mkdir /usr/local/awstats

Put all files from the package over there.

cd /usr/local/awstats

tar xzf /root/awstats-6.9.tar.gz

Make configuration directory for awstats.

mkdir /etc/awstats

In case you have old configuration files, just copy them over as :-

cp /data/backup/etc/awstats/awstats.* /etc/awstats/

Or, create new ones as following. Remember to use the naming scheme as ” awstats._sitename.conf “

The important lines are highlighted.

[root@www root]# vi /etc/awstats/awstats.www.example.com.conf

LogFile=”/var/www/vhosts/example.com/statistics/logs/access_log”

LogType=W

LogFormat=4

LogSeparator=” “

SiteDomain=”www.example.com”

HostAliases=”example.com www.example.com 127.0.0.1 localhost”

DNSLookup=1

DirData=”/var/lib/awstats”

DirCgi=”/cgi-bin”

DirIcons=”/icon”

AllowToUpdateStatsFromBrowser=0

AllowFullYearView=2

EnableLockForUpdate=0

DNSStaticCacheFile=”dnscache.txt”

DNSLastUpdateCacheFile=”dnscachelastupdate.txt”

SkipDNSLookupFor=””

AllowAccessFromWebToAuthenticatedUsersOnly=0

AllowAccessFromWebToFollowingAuthenticatedUsers=””

AllowAccessFromWebToFollowingIPAddresses=””

CreateDirDataIfNotExists=0

BuildHistoryFormat=text

BuildReportFormat=html

SaveDatabaseFilesWithPermissionsForEveryone=0

PurgeLogFile=0

ArchiveLogRecords=0

KeepBackupOfHistoricFiles=0

DefaultFile=”index.html”

SkipHosts=””

SkipUserAgents=””

SkipFiles=””

SkipReferrersBlackList=””

OnlyHosts=””

OnlyUserAgents=””

OnlyFiles=””

NotPageList=”css js class gif jpg jpeg png bmp ico swf”

ValidHTTPCodes=”200 304”

ValidSMTPCodes=”1 250”

AuthenticatedUsersNotCaseSensitive=0

URLNotCaseSensitive=0

URLWithAnchor=0

URLQuerySeparators=”?;”

URLWithQuery=0

URLWithQueryWithOnlyFollowingParameters=””

URLWithQueryWithoutFollowingParameters=””

URLReferrerWithQuery=0

WarningMessages=1

ErrorMessages=””

DebugMessages=0

NbOfLinesForCorruptedLog=50

WrapperScript=””

DecodeUA=0

MiscTrackerUrl=”/js/awstats_misc_tracker.js”

UseFramesWhenCGI=1

DetailedReportsOnNewWindows=1

Check the directory:-

[root@www awstats-6.9]# ls /etc/awstats/ -l

-rw-r–r– 1 root root 59622 Jul 29 12:21 awstats.www.example.com.conf

[root@www awstats-6.9]#

The Data directory is /var/lib/awstats

mkdir /var/lib/awstats

Optional : If you have old data, you can copy it to the /var/lib/awstats at this point.

cp /data/backup/var/lib/awstats/* /var/lib/awstats/

Add the highlighted code to your apache virtual hosts configuration:

<VirtualHost *:80>

ServerName www.example.com

ServerAlias example.com

DocumentRoot /var/www/html/default

< Directory /var/www/html/default >


Order Allow,Deny

AllowOverride none

Allow from all

Options None

< /Directory >


ErrorLog /var/www/vhosts/example.com/statistics/logs/error_log

CustomLog /var/www/vhosts/example.com/statistics/logs/access_log common

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/”

#

# This is to permit URL access to scripts/files in AWStats directory.

#

<Directory “/usr/local/awstats/wwwroot”>


Options None

AllowOverride None

Order allow,deny

Allow from all

</Directory>


</VirtualHost>

Create records from the log file for the first time. (This is a very slow process. 4500 lines per second + DNS overhead, on a 1 GHz system). Will take an hour sometimes:-


[root@www root]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.example.com -update

Create/Update database for config “/etc/awstats/awstats.www.example.com.conf” by AWStats version 6.9 (build 1.925)

From data in log file “/var/www/vhosts/example.com/statistics/logs/access_log”…

Phase 1 : First bypass old records, searching new record…

Direct access to last remembered record has fallen on another record.

So 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: 4460803

Found 10 dropped records,

Found 399 corrupted records,

Found 4096243 old records,

Found 364151 new qualified records.

[root@www root]#

Put the following in crontab to run everymorniing at 4 AM. Use multiple entries for each site you are monitoring with awstats.


crontab -e

0 4 * * * /usr/bin/perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.example.com -update


That is it.

Access your stats page using :

http://www.example.com/awstats/awstats.pl

Making your stats in-accessible to public:-

Create a .htaccess file in the wwwroot/cgi-bin directory:

vi .htaccess

AuthName “Authorization Required”
AuthType Basic
AuthUserFile /var/www/vhosts/.htpasswd
Require valid-user

Create users such as:-

[root@www cgi-bin]# htpasswd -c /var/www/vhosts/.htpasswd example.com


New password:
Re-type new password:


Change ownership of the .htaccess and .htpasswd files to make them readable by apache:

chown apache:apache .htaccess /var/www/vhosts/.htpasswd

For this to work, you will need to update the corresponding AllowOverride directive in your apache config file,

From:

AllowOverride None

To :

AllowOverride AuthConfig
Or:

AllowOverride All

Then restart or reload Apache service:

service httpd reload

That should be all.