Step # 1
1) Visit AWStats project home page http://awstats.sourceforge.net/ to download source code or RPM file of awstats. I prefer to use RPM. At the time of writing this latest version of awstats was stable 6.2-1. Here is wget command to download file (make sure you replace appropriate version number in download):
# wget http://prdownloads.sourceforge.net/awstats/awstats-6.2-1.noarch.rpm
Step # 2
Now Install awstats the easiest way to install awstats is use rpm command:
# rpm -ivh awstats-6.2-1.noarch.rpm
Step # 3
Once AWstats installed, it is time to configure it. Fortunately it comes with nice configuration perl script:
1) Change current directory to /usr/local/awstats/tools where awstats configuration tools installed:
# cd /usr/local/awstats/tools
2) Make sure you know the domain’s access log file. Check apache configuration file /etc/httpd/conf/httpd.conf and look for access_log parameter. A quick grep will help you to find out your access log file:
# grep “CustomLog” etc/httpd/conf/httpd.conf
3) Run awstats_configure.pl script to configure awstats (this perl script will do little modification to your httpd.conf file. Here is typical session from above script [required input shown in BOLD + UNDERLINE text]):
# ./awstats_configure.pl
—–> Check and complete web server config file \’/etc/httpd/conf/httpd.conf\’
Add ‘Alias /awstatsclasses “/usr/local/awstats/wwwroot/classes/”‘
Add ‘Alias /awstatscss “/usr/local/awstats/wwwroot/css/”‘
Add ‘Alias /awstatsicons “/usr/local/awstats/wwwroot/icon/”‘
Add ‘ScriptAlias /awstats/ “/usr/local/awstats/wwwroot/cgi-bin/”‘
Add ” directive
AWStats directives added to Apache config file.
—–> Update model config file ‘/etc/awstats/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.cyberciti.biz
—–> 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): <PRESS ENTER KEY>
—–> Create config file ‘/etc/awstats/awstats.www.cyberciti.biz.conf’
Config file /etc/awstats/awstats.www.cyberciti.biz.conf created.
—–> Restart Web server with ‘/sbin/service httpd restart’
Stopping httpd: [ OK ]
Starting httpd: [ 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:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.cyberciti.biz
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue…
A SIMPLE config file has been created: /etc/awstats/awstats.www.cyberciti.biz.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘www.cyberciti.biz’ with command:
> perl awstats.pl -update -config=www.cyberciti.biz
You can also read your statistics for ‘www.cyberciti.biz’ with URL:
> http://localhost/awstats/awstats.pl?config=www.cyberciti.biz
Press ENTER to finish…
In above session you need to input three different things.
(A) Answer question “Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ?” with y
(B) Answer question “Your web site, virtual server or profile name:” with your domain name. For example www.cyberciti.biz.
(C) Answer question “Directory path to store config file(s) (Enter for default):” Press enter key to accept default /etc/awstats directory to store configuration for domain.
5) Open your configuration file created by previous script using text editor:
# vi /etc/awstats/awstats.www.cyberciti.biz.conf
6) Look for LogFile parameter and set value to your actual access_log file:
For example:
LogFile=”/home/httpd/vhosts/cyberciti.biz/statistics/logs/access_log”
7) Create directory to store some initial data:
# mkdir -p /var/lib/awstats
Create directory to store awstats html pages so that it can be viewed/analyzed from web browser(create appropriate directory according to your need):
# mkdir -p /home/httpd/vhosts/cyberciti.biz/httpdocs/tools/awstats
9) Build all sorts of webpage’s by running command:
(a) Change Directory:
# cd /usr/local/awstats/tools
(b) Run perl script to build stats:
# ./awstats_buildstaticpages.pl -config=www.cyberciti.biz -update -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/home/httpd/vhosts/cyberciti.biz/httpdocs/tools/awstats/
Where
-config : Name of file for your domain stored in /etc/awstats or file which you modified step # 3 (5)
-update : Update statistics
-awstatsprog : Path to awstats.pl script to generate all statistics
-dir : Directory in which you need to store generated html statistics
10) It is time to test generated web pages aka stats. Fire FireFox (upgrade Internet explorer to FireFox!) and type url http://www.yourdomain.com/path/to/awstats/.
11) Tip you may find that you lost old month statistics with Awstats. To get your old stats you simply need to run following command:
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.cyberciti.biz -update -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/home/httpd/vhosts/cyberciti.biz/httpdocs/tools/awstats/ -month=12 -year=2004
Please replace values of month and year according to your need.
Step # 4: Setup cron job
1) Edit existing contrab:
# crontab -e
2) Add entry to it (here I am generating stats every 10 minutes; generally, you should setup cron, according to your own requirements):
# 10 * * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.cyberciti.biz -update -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/home/httpd/vhosts/cyberciti.biz/httpdocs/tools/awstats/ >/dev/null 2>&1
Note command must type in one line or spanned using \
3) Once cron job saved, you need to make sure that crond service running following command ensures that:
a) See if crond running or not:
# service crond status
crond (pid 1519) is running…
b) If it is not running then start it:
# service crond start
c) Make sure crond starts everytime linux comes up after reboot/shutdow:
# chkconfig crond on
Step # 5 Security
Well awstats does not open any port or open any major security risks. However, generally you should consider two important things:
1) Protect your AWstats html pages with password-protected directory. Use apache’s simple directory protection mechanism. This can easily accomplished with .htaccess file in your /path/to/awstats/ directory. You are going to use directory protection using apache’s .htaccess and .htpasswd :
(a) Create .htaccess file in /home/httpd/vhosts/cyberciti.biz/httpdocs/tools/awstats/ directory (add text as follows)
vi /home/httpd/vhosts/cyberciti.biz/httpdocs/tools/awstats/.htaccess
AuthName “AWStats restricted access”
AuthType Basic
AuthUserFile /home/httpd/vhosts/cyberciti.biz/private/.htpasswd
require user awstatsadmin
(b) Create user and password (-c assumes first time you are using .htpasswd file, otherwise skip this directive):
# htpasswd -c /home/httpd/vhosts/cyberciti.biz/private/.htpasswd awstatsadmin
For more information please read documents:
Authentication and access control
.htaccess other options/directives
2) Remember all logs rotated on regular basis including apache. Therefore, it is necessary to make sure that awstats does not misses your statistics. In logrotate httpd configuration file you need to add following 3 lines after /var/log/httpd/*log {:
(a) Open /etc/logrotate.d/httpd in vi text editor:
/etc/logrotate.d/httpd
(b) Add following following 3 lines after /var/log/httpd/*log {:
sharedscripts
prerotate
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.cyberciti.biz – update -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/home/httpd/vhosts/cyberciti.biz/httpdocs/tools/awstats/ >/dev/null 2>&1
endscript
As a result, before log rotating take place our perl script will be execute to generate html stats.