Awstats

tis a small tutorial on Awstats, we suppose that you already have Apache installed and working on your serrver.

get and uncompress the program

you will need to get Awstats from http://awstats.sourceforge.net/#DOWNLOAD (i used awstats-6.7.tar.gz for this tutorial)

so you can do something like:

cd /usr/local/ wget http://the_link_to_get_awstats

decompress and install awstats

tar zxvf awstats-6.7.tar.gz mv awstats-6.7 /usr/local/awstats chown -R root:www-data /usr/local/awstats chmod 750 /usr/local/awstats mkdir /var/cache/awstats chown www-data:www-data /var/cache/awstats

configure Awstats

to simplify things you can get some \"home made\" default configuration files and then modify them:

mkdir /etc/awstats cd /etc/awstats wget http://manurevah.com/stuff/awstats/awstats.domaine.tld.conf wget http://manurevah.com/stuff/awstats/include.conf

then copy awstats.domaine.tld.conf to awstats.mywebsite.com.conf, you can repeat this for the web sites you wish to have Awstats statistics.

cp awstats.domaine.tld.conf awstats.mywebsite.com.conf

in your new file you\'ll need to modify:

LogFile=\"/var/log/apache/mywebsite.com.log\" # this should be the apache log file of the vhost SiteDomain=\"monsiteamoi.com\" # the domain name HostAliases=\"www.monsiteamoi.com\"

Updating the statistics

we shall create a little script that will be executed by crontab

vi /usr/local/sbin/awstats-cronbin

and we should insert

#!/bin/bash perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mywebsite.com perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=example.com

then make it executable

chmod +x /usr/local/sbin/awstats-cronbin

and now tell crontab to do something;

echo \"0 6,12,18,22 * * * root /usr/local/sbin/awstats-cronbin\" >> /etc/crontab

Apache configuration

to consult the stats we will be going through apache, you can have a global access to Awstats (bad) or make it available only to a virtual host (good). in this example i\'ll configure the subdomain stats.monsiteamoi.com for consulting the stats, this does however imply that you know something about Apache so you can adapt this to your setup..

<VirtualHost *:80> ServerName stats.mywebsite.com DocumentRoot /var/www/html/user/stats.monsiteamoi.com CustomLog /var/log/apache2/stats.monsiteamoi.com.log combined # Configuration pour Awstats <Directory \"/usr/local/awstats/wwwroot\"> Options None AllowOverride AuthConfig Order allow,deny Allow from all </Directory> 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/\" </VirtualHost>

make sue that in each concerned virtual host the logs are created as follows for this is what Awstats will need to read from.

CustomLog /var/log/apache/domain.tld.log combined

now we need to restart apache, always check your configuration before otherwise your billions of visitors might not be able to access your advertisement server while you repare.. :]

apachectl configtest apachectl graceful

looking at stats

all you need to do is point your browser to the virtual host previously configured for this purpose, in this example it\'s stats.mywebsite.com, then to the awstats perl script with the domain name stats to consult as an argument. the part: config=mywebsite.com will look in /etc/awstats for a file named awstats.mywebsite.com.conf.

in short: http://stats.mywebsite.com/awstats/awstats.pl?config=mywebsite.com

security

you can secure access with an .htacces file and/or directly from withing Apache\'s configuration:

<Files \"awstats.pl\"> AuthUserFile /var/www/.htpasswd # make sure you have this htpasswd file AuthGroupFile /dev/null AuthName \"mdp stp\" AuthType Basic require valid-user AllowOverride AuthConfig </Files>

for now we are done, you can now tweak and tell me about it if you\'d like