If you’ve ever seen an Apache log file, you’ll notice that it’s rather long to read. It’s not that the log is hard to read, it’s just full of a lot of useless information. If you view a website with a browser, the log will show that you connect and retrieve every single file (images are included). Ouch.
I installed Debian 5.0 Server on an HP DL380 G4 server. I then did all the updates etc. I’m assuming you know how to install apache and how to “su” to root.
apt-get install awstats
nano /etc/apache2/awstats.conf
This creates a new file called 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
Save this file and exit back to the shell.
nano /etc/apache2/apache2.conf
Add this to the end of the conf file:
Include /etc/apache2/awstats.conf
Save and exit apache.conf.
apache2ctl restart
cd /etc/awstats
cp awstats.conf awstats.www.mysite.org.conf
nano awstats.www.mysite.org.conf
Search for and edit the following:
LogFile=”/var/log/apache2/access.log”
SiteDomain=”mysite.org”
Save the file and exit to the shell.
Now we need to run the script to parse the log files into a stats page:
perl /usr/lib/cgi-bin/awstats.pl -update -config=www.mysite.org
If it fails due to permissions:
chmod -R 777 /var/log/apache2
Then re-run the script
Now check your stats at http://www.mysite.org/awstats/awstats.pl
As long as everything went to plan, the script should also automatically install a cron job to update the stats every 10 minutes.
You can find out by typing the following:
dpkg -L awstats | grep cron
Which shows the following:
/etc/cron.d
/etc/cron.d/awstats
If you nano the awstats cron, you can edit the times and locations of the scripts.
EDIT!!!
If you’re using virtual hosts (like I am) and you want each site to have its own stats:
Edit your sites-available default:
nano /etc/apache2/sites-available/default
Add the following in your VirtualHost:
NameVirtualHost 192.168.1.4
DocumentRoot “/var/www/web123”
ServerName web123.com
ServerAlias *.web123.com
CustomLog /var/log/apache2/web123.com.log combined
Then you’ll have to create the awstats.web123.com.conf file in /etc/awstats
cp /etc/awstats/awstats.conf /etc/awstats/awstats.web123.com.conf
nano /etc/awstats/awstats.web123.com.conf
Change the following:
LogFile=”/var/log/apache2/web123.com.log”
LogFormat=1
SiteDomain=”web123.com”
HostAliases=”web123.com www.web123.com localhost 127.0.0.1″
This will allow you to use the browser to update the stats if your CRON job is set for long periods of time:
AllowToUpdateStatsFromBrowser=1
And I set this up because I have apache do a DNS lookup on its own:
DNSLookup=0
Then restart apache:
apache2ctl restart