Todd Smith Org

March 18, 2009

Setup AWStats on Linux with Custom Apache

Filed under: Web Hosting — admin @ 9:45 pm

I need to install awstats. I am too lazy tonight to go and install the package myself, so I’ll just use apt.

Update: This was going to be for Ubuntu, but will work on any Unix include Solaris, HP-UX, FreeBSD, OpenBSD, Slackware, CentOS…… Whatever.

Installation

wget http://superb-east.dl.sourceforge.net/sourceforge/awstats/awstats-6.9.tar.gz
mkdir /opt
tar zxvf awstats-6.9.tar.gz -C /opt
ln -sf /opt/awstats-6.9 /opt/awstats

Now, it’s installed. Time to Configure.

Configuration

cd /opt/awstats
perl tools/awstats_configure.pl

root@function:/opt/awstats# perl tools/awstats_configure.pl

—– AWStats awstats_configure 1.0 (build 1.8) (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:
/opt/awstats-6.9
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] ?
root@function:/opt/awstats# perl tools/awstats_configure.pl

—– AWStats awstats_configure 1.0 (build 1.8) (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:
/opt/awstats-6.9
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):
> /opt/apache/conf/httpd.conf

—–> Check and complete web server config file ‘/opt/apache/conf/httpd.conf’
Warning: You Apache config file contains directives to write ‘common’ log files
This means that some features can’t work (os, browsers and keywords detection).
Do you want me to setup Apache to write ‘combined’ log files [y/N] ? y
Add ‘Alias /awstatsclasses “/opt/awstats-6.9/wwwroot/classes/”‘
Add ‘Alias /awstatscss “/opt/awstats-6.9/wwwroot/css/”‘
Add ‘Alias /awstatsicons “/opt/awstats-6.9/wwwroot/icon/”‘
Add ‘ScriptAlias /awstats/ “/opt/awstats-6.9/wwwroot/cgi-bin/”‘
Add ‘<Directory>’ directive
AWStats directives added to Apache config file.

—–> Update model config file ‘/opt/awstats-6.9/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:
> www.toddsmith.org

—–> 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.www.toddsmith.org.conf’
Config file /etc/awstats/awstats.www.toddsmith.org.conf created.

—–> Restart Web server with ‘/etc/init.d/apache restart’
Stopping Apache…OK
Starting Apache…OK

—–> 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:
/opt/awstats-6.9/wwwroot/cgi-bin/awstats.pl -update -config=www.toddsmith.org
Or if you have several config files and prefer having only one command:
/opt/awstats-6.9/tools/awstats_updateall.pl now
Press ENTER to continue…

A SIMPLE config file has been created: /etc/awstats/awstats.www.toddsmith.org.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘www.toddsmith.org’ with command:
> perl awstats.pl -update -config=www.toddsmith.org
You can also read your statistics for ‘www.toddsmith.org’ with URL:
> http://localhost/awstats/awstats.pl?config=www.toddsmith.org

Press ENTER to finish…

root@function:/opt/awstats#

Now I feel like my httpd.conf has just been molested, I’m gonna go fix it. The following was added:

#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses “/opt/awstats-6.9/wwwroot/classes/”
Alias /awstatscss “/opt/awstats-6.9/wwwroot/css/”
Alias /awstatsicons “/opt/awstats-6.9/wwwroot/icon/”
ScriptAlias /awstats/ “/opt/awstats-6.9/wwwroot/cgi-bin/”

#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory “/opt/awstats-6.9/wwwroot”>
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>

I’m gonna change this up a little bit, make it easier to manage, and easier to upgrade at the same time.

cat<<EoF>/opt/apache/conf/awstats.conf

#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses “/opt/awstats/wwwroot/classes/”
Alias /awstatscss “/opt/awstats/wwwroot/css/”
Alias /awstatsicons “/opt/awstats/wwwroot/icon/”
ScriptAlias /awstats/ “/opt/awstats/wwwroot/cgi-bin/”

#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory “/opt/awstats/wwwroot”>
Options SymLinksIfOwnerMatch
AllowOverride AuthConfig FileInfo
Order deny,allow
Allow from all
AuthName “AWStats”
AuthType Basic
AuthUserFile /vhosts/auth/webadmin.pwd
require valid-user
</Directory>

EoF

So I made myself a custom configuration file, and a complementary script. This works well for me because I keep all my virtual hosts in /vhosts and their logs under log/xfer_log.

Awstats Configuration File

LogFile=”/vhosts/REPLACE_ME/log/xfer_log”
LogType=W
LogFormat=1
LogSeparator=” ”
SiteDomain=”REPLACE_ME”
HostAliases=”REPLACE_ME www.REPLACE_ME 127.0.0.1 localhost”
DNSLookup=2
DirData=”/vhosts/REPLACE_ME/htdocs/stats”
DirCgi=”/awstats”
DirIcons=”/awstatsicons”
AllowToUpdateStatsFromBrowser=0
AllowFullYearView=3
EnableLockForUpdate=0
DNSStaticCacheFile=”dnscache.txt”
DNSLastUpdateCacheFile=”dnscachelastupdate.txt”
SkipDNSLookupFor=”"
AllowAccessFromWebToAuthenticatedUsersOnly=1
AllowAccessFromWebToFollowingAuthenticatedUsers=”webadmin awstats”
AllowAccessFromWebToFollowingIPAddresses=”"
CreateDirDataIfNotExists=0
BuildHistoryFormat=text
BuildReportFormat=html
SaveDatabaseFilesWithPermissionsForEveryone=0
PurgeLogFile=0
ArchiveLogRecords=0
KeepBackupOfHistoricFiles=0
DefaultFile=”index.html”
SkipHosts=”"
SkipUserAgents=”"
SkipFiles=”"
SkipReferrersBlackList=”"
OnlyHosts=”"
OnlyUserAgents=”"
OnlyUsers=”"
OnlyFiles=”"
NotPageList=”css js class gif jpg jpeg png bmp ico rss xml 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”
LevelForBrowsersDetection=2 # 0 disables Browsers detection.
# 2 reduces AWStats speed by 2%
# allphones reduces AWStats speed by 5%
LevelForOSDetection=2 # 0 disables OS detection.
# 2 reduces AWStats speed by 3%
LevelForRefererAnalyze=2 # 0 disables Origin detection.
# 2 reduces AWStats speed by 14%
LevelForRobotsDetection=2 # 0 disables Robots detection.
# 2 reduces AWStats speed by 2.5%
LevelForSearchEnginesDetection=2 # 0 disables Search engines detection.
# 2 reduces AWStats speed by 9%
LevelForKeywordsDetection=2 # 0 disables Keyphrases/Keywords detection.
# 2 reduces AWStats speed by 1%
LevelForFileTypesDetection=2 # 0 disables File types detection.
# 2 reduces AWStats speed by 1%
LevelForWormsDetection=0 # 0 disables Worms detection.
# 2 reduces AWStats speed by 15%
UseFramesWhenCGI=1
DetailedReportsOnNewWindows=1
Expires=0
MaxRowsInHTMLOutput=1000
Lang=”auto”
DirLang=”./lang”
ShowMenu=1
ShowSummary=UVPHB
ShowMonthStats=UVPHB
ShowDaysOfMonthStats=VPHB
ShowDaysOfWeekStats=PHB
ShowHoursStats=PHB
ShowDomainsStats=PHB
ShowHostsStats=PHBL
ShowAuthenticatedUsers=0
ShowRobotsStats=HBL
ShowWormsStats=0
ShowEMailSenders=0
ShowEMailReceivers=0
ShowSessionsStats=1
ShowPagesStats=PBEX
ShowFileTypesStats=HB
ShowFileSizesStats=0
ShowOSStats=1
ShowBrowsersStats=1
ShowScreenSizeStats=0
ShowOriginStats=PH
ShowKeyphrasesStats=1
ShowKeywordsStats=1
ShowMiscStats=a
ShowHTTPErrorsStats=1
ShowSMTPErrorsStats=0
ShowClusterStats=0
AddDataArrayMonthStats=1
AddDataArrayShowDaysOfMonthStats=1
AddDataArrayShowDaysOfWeekStats=1
AddDataArrayShowHoursStats=1
IncludeInternalLinksInOriginSection=0
MaxNbOfDomain = 10
MinHitDomain = 1
MaxNbOfHostsShown = 10
MinHitHost = 1
MaxNbOfLoginShown = 10
MinHitLogin = 1
MaxNbOfRobotShown = 10
MinHitRobot = 1
MaxNbOfPageShown = 10
MinHitFile = 1
MaxNbOfOsShown = 10
MinHitOs = 1
MaxNbOfBrowsersShown = 10
MinHitBrowser = 1
MaxNbOfScreenSizesShown = 5
MinHitScreenSize = 1
MaxNbOfWindowSizesShown = 5
MinHitWindowSize = 1
MaxNbOfRefererShown = 10
MinHitRefer = 1
MaxNbOfKeyphrasesShown = 10
MinHitKeyphrase = 1
MaxNbOfKeywordsShown = 10
MinHitKeyword = 1
MaxNbOfEMailsShown = 20
MinHitEMail = 1
FirstDayOfWeek=1
ShowFlagLinks=”"
ShowLinksOnUrl=1
UseHTTPSLinkForUrl=”"
MaxLengthOfShownURL=64
HTMLHeadSection=”"
HTMLEndSection=”"
Logo=”awstats_logo6.png”
LogoLink=”http://awstats.sourceforge.net”
BarWidth = 260
BarHeight = 90
StyleSheet=”"
color_Background=”FFFFFF” # Background color for main page (Default = “FFFFFF”)
color_TableBGTitle=”CCCCDD” # Background color for table title (Default = “CCCCDD”)
color_TableTitle=”000000″ # Table title font color (Default = “000000″)
color_TableBG=”CCCCDD” # Background color for table (Default = “CCCCDD”)
color_TableRowTitle=”FFFFFF” # Table row title font color (Default = “FFFFFF”)
color_TableBGRowTitle=”ECECEC” # Background color for row title (Default = “ECECEC”)
color_TableBorder=”ECECEC” # Table border color (Default = “ECECEC”)
color_text=”000000″ # Color of text (Default = “000000″)
color_textpercent=”606060″ # Color of text for percent values (Default = “606060″)
color_titletext=”000000″ # Color of text title within colored Title Rows (Default = “000000″)
color_weekend=”EAEAEA” # Color for week-end days (Default = “EAEAEA”)
color_link=”0011BB” # Color of HTML links (Default = “0011BB”)
color_hover=”605040″ # Color of HTML on-mouseover links (Default = “605040″)
color_u=”FFAA66″ # Background color for number of unique visitors (Default = “FFAA66″)
color_v=”F4F090″ # Background color for number of visites (Default = “F4F090″)
color_p=”4477DD” # Background color for number of pages (Default = “4477DD”)
color_h=”66DDEE” # Background color for number of hits (Default = “66DDEE”)
color_k=”2EA495″ # Background color for number of bytes (Default = “2EA495″)
color_s=”8888DD” # Background color for number of search (Default = “8888DD”)
color_e=”CEC2E8″ # Background color for number of entry pages (Default = “CEC2E8″)
color_x=”C1B2E2″ # Background color for number of exit pages (Default = “C1B2E2″)
ExtraTrackedRowsLimit=500

Update Script

#!/bin/bash
cd /etc/awstats
webserver_user=daemon

for each in `ls -1 –color=none /vhosts` ; do
if [ X"$1" = "Xclean" ] ; then
rm -rf /vhosts/$each/htdocs/stats
fi
if [ ! -d /vhosts/$each/htdocs/stats ] ; then
mkdir /vhosts/$each/htdocs/stats
fi
chown -R $webserver_user /vhosts/$each/htdocs/stats
cat awstats.REPLACE_ME.conf | sed s,REPLACE_ME,$each,g > awstats.$each.conf
su $webserver_user -c “/opt/awstats/wwwroot/cgi-bin/awstats.pl -update -config=$each”
done

touch update_awstats.lastrun

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress