AWStats Installation
From DreamHost
AWStats is an alternative Web log analyzer that offers a wider range of statistics than Analog.
This guide assumes that your username is yourusername and your domain is example.com. You should change it to fit your username and domain.
| The instructions provided in this article or section require shell access unless otherwise stated. You can use the PuTTY client on Windows, or SSH on UNIX and UNIX-like systems such as Linux or Mac OS X. |
Contents |
Download
Get into the correct directory
cd ~/
Download AWStats, get latest from [1].
wget http://awstats.sourceforge.net/files/awstats-6.7.tar.gz
Extract the TAR
tar xfzv awstats-6.7.tar.gz
Rename the awstats folder and then go to the awstats folder.
mv awstats-6.7 awstats cd awstats
You should now have a directory:
/home/yourusername/awstats
Installation
Static Pages
Changing the Directory Structure
Create a directory named 'data' and change the permissions.
cd ~/awstats mkdir data chmod 755 data
Move the files in the /home/yourusername/awstats/wwwroot/cgi-bin/ directory into /home/yourusername/awstats/.
mv ~/awstats/wwwroot/cgi-bin ~/awstats
Setting up the Domain Name
Create a directory in your domain folder (substitute your domain for "domainname.com").
mkdir ~/domainname.com/statistics
Copy the following:
- icon
- css
- js
To the statistics folder in your domain folder. (substitute your domain for "domainname.com")
cp -r ~/awstats/wwwroot/{icon,css,js} ~/domainname.com/statistics
It should be noted that you should not call the directory 'stats'. DH uses 'domainname.com/stats' as a default for their Analog statistics.
Configuration
In the awstats/cgi-bin/ folder, copy awstats.model.conf to awstats.domainname.com.conf, where "domainname.com" is actually your website domain.
cp ~/awstats/cgi-bin/awstats.model.conf ~/awstats/cgi-bin/awstats.domainname.com.conf
Open the file for editing
vi ~/awstats/cgi-bin/awstats.domainname.com.conf
Change the following parameters in the file
- Set the changes to the following changing the yourusername and example.com to your information.
- Save or upload the file if you didn't use 'vi'.
#Dreamhost rotates the logs and the logresolvemerge.pl below makes sure that you get the previous logs too. LogFile="/home/yourusername/awstats/tools/logresolvemerge.pl /home/yourusername/logs/domainname.com/http/access.log*|" LogFormat="%host %other %other %time1 %methodurl %code %bytesd %refererquot %uaquot" SiteDomain="domainname.com" HostAliases="www.domainname.com" DNSLookup=0 DirData="/home/yourusername/awstats/data/" DirIcons="icon" SaveDatabaseFilesWithPermissionsForEveryone=0 DefaultFile="index.php index.html"
If you did use 'vi', hit Esc, type :x, and hit Enter. This will save your changes and exit you out of the editor.
Checking AWStats
Verify that all of your *.pl files are with 755 permissions. The first column of output should read: -rwxr-xr-x.
ls -o
If some don't look like that, then you can run this:
find . -name '*.pl' | xargs chmod 755
Then run
ls -o
again to see that they're all correct now.
Check that everything is working
perl /home/yourusername/awstats/tools/awstats_buildstaticpages.pl -config=domainname.com -update \ -awstatsprog=/home/yourusername/awstats/cgi-bin/awstats.pl -dir=/home/yourusername/domainname.com/statistics/
- The above has been entered as two lines. If entered in one line, remove the backslash (\)
Check the output folder (/statistics/) in your browser. Look at the awstats.domainname.com.html file. Does everything look good? Great! Then let's setup a cron job to do this automatically.
NOTE: If you have a Ruby on Rails site, you will not be able to see this output with your browser. One way to get around this problem is to change the last part of the command to this:
-dir=/home/yourusername/domainname.com/public/statistics/
CRON Script
The Crontab page will be of some use if you are having trouble.
Edit the crontab
crontab -e
Insert the following
- If the line is too large in the default editor than it will fall to the next line, you will have to manually go back and press delete to make sure it is all on the same line. It all must be on the same line.
- As always, change the yourusername and domainname.com to your information.
- The following has been moved to three lines to save from side scrolling, it still needs to be one line.
0 3 * * * /usr/local/bin/perl /home/yourusername/awstats/tools/awstats_buildstaticpages.pl -config=domainname.com -update -awstatsprog=/home/yourusername/awstats/cgi-bin/awstats.pl -dir=/home/yourusername/domainname.com/statistics/ >/dev/null 2>&1
The >/dev/null 2>&1 is to prevent the job from mailing you the results every time the script runs. The mail ends up in /home/username/MailDir
Replace with >/dev/null to just receive errors
Save and close
CTRL + O To Save Press Enter To Overwrite the File CTRL + X To Quit
- Note about crontab: you must specify a full path to perl or the script will not work.
.htaccess file
Edit the .htaccess file in the output directory (domainname.com/statistics/) and type the following.
DirectoryIndex awstats.example.com.html
That will show the stats overview as the default index when you open "www.example.com/statistics/". You might also want to password protect it.
Alternative
If for some reason .htaccess files do not work, creating a symbolic link can achieve the same result
ln -s ~/domainname.com/statistics/awstats.example.com.html ~/domainname.com/statistics/index.html
AWStats For Another Domain
- Repeat the 'Configure' step for the domain name.
- Repeat the 'Setting up the Domain Name' step and copy the folders to the domain name.
- Repeat 'Crontab' step by adding a new line and changing the details for the other domain name.
- Change the new crontab time by changing the first number to increments of 15 or whatever number besides that of the last one and the second number to the same unless you would have two running at the same time.
- Repeat the '.htaccess file' step for the new domain.
- And run this to create the stats for the first time.
perl /home/yourusername/awstats/tools/awstats_buildstaticpages.pl -config=example2.com \ -update -awstatsprog=/home/yourusername/awstats/cgi-bin/awstats.pl \ -dir=/home/yourusername/example2.com/statistics/
Dynamic pages
- There's an dynamic setup available here: AWStats_Installation_(alternative). It allows the data to be dynamically updated through the browser (real-time data update), and access to previous months (or yearly) data.
Quick
Remove 'Useless' Files
Go to the awstats folder (if you renamed the directory then go to that)
cd awstats
Remove all the files except for the wwwroot folder
rm -rf README.TXT rm -rf docs
Then move the contents of wwwroot to the current directory
mv wwwroot/* .
Configuration
Change to the cgi-bin folder
cd cgi-bin
Here there is an example configuration.
- Want to copy and edit this.
- Do this for as many domains as you have.
cp awstats.model.conf awstats.mydomain1.com.conf cp awstats.model.conf awstats.mydomain2.com.conf cp awstats.model.conf awstats.mydomain3.com.conf
Now, editing the config. Things should be set as follows: (You can skip this bit and use the Config Generator)
LogFile="/home/YourUserName/logs/YourDomain/http/access.log" SiteDomain="YourDomain" HostAliases="localhost 127.0.0.1 REGEX[YourDomain\.TLD$]" DirData="/home/YourUserName/YourDomain/AWStatsFolder" AllowToUpdateStatsFromBrowser=1
That should do it, to test it out open
http://YourDomain/AwStatsDir/cgi-bin/awstats.pl?config=YourDomain
Update the Stats
You can update the stats from your browser.
If you want to use crontab
crontab -e
Then type on a line, which will update the stats every hour.
0 * * * * /home/YourUserName/YourDomain/AwStatsDir/cgi-bin/awstats.pl -config=mysite -update >/dev/null
Changing the Permissions
If you changed the awstats folder, just replace the awstats-6.5 to that of your awstats folder.
chmod -R 755 awstats-6.5
This will fix the 500 Internal Server Error and Premature end of script headers in your server error log.
Importing your old log files
To run AWStats on all of your old logs, you can create a shell script (found at http://floatingsun.net/blog/articles/awstats-textdrive/).
Make sure your AWStats data directory is empty before you run the script.
In a text editor (like vi or pico), create a shell script.
pico parse_old_stats
Enter the following
for log in $(ls -rt ~/logs/example.com/http/access*.gz) do echo $log echo “zcat” zcat $log > ~/tmp/access_log sleep 5 echo “awstats.pl” ./awstats/cgi-bin/awstats.pl -update -config=example.com -LogFile=/home/yourusername/tmp/access_log sleep 5 done
Make sure the script can run
chmod 755 parse_old_stats
The sleep commands give AWStats enough time to process between log files.
Alternative old log files import
You can also use the Logresolvemerge tool provided with AWStats (in tools directory) replacing:
LogFile="/home/yourusername/awstats/tools/logresolvemerge.pl /home/yourusername/logs/example.com/http/access*.* |"
in the awstats.domainname.com.conf configuration file for the first run. See the Awstats FAQs: http://awstats.sourceforge.net/docs/awstats_faq.html#OLDLOG and http://awstats.sourceforge.net/docs/awstats_faq.html#MULTILOG for details.
Notes
- You can make any other changes you deem useful to the config file, it's decently commented. Also, if your log files are very large (you get lots of hits), you'll probably have to run awstats once daily to put less strain on the server. There are some guidelines for that on the AwStats website. You'd have to change the logfile location in that case too, to use the current log.
External Links
- Notes by Skybly - in the DreamHost forums on installation info.
- AWStats Hack - Discussion regarding a hack of awstats that over-writes your index.php files. Only for dynamic installations and in versions previous than 6.4.

