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 - in this example it assumes you're installing the awstats in your local directory so go to your local home root:
cd ~/
Download AWStats, get latest from [1].
wget http://awstats.sourceforge.net/files/awstats-6.9.tar.gz
Extract the TAR
tar xfzv awstats-6.9.tar.gz
Rename the awstats folder and then go to the awstats folder.
mv awstats-6.9 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
You may need to make the file writable before editing.
chmod 644 ~/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. For example, you have to fill out the MAILTO="" field in order for Dreamhost to use your crontab.
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/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.
Installing JAWStats for use with AWStats
JAWStats is not an AWStats replacement. Instead it runs in conjunction with AWStats and produces attractive, clear and informative charts, graphs and tables about your website visitors.
The steps required to install JAWStats begin with the installation of AWStats as outlined above (which a few very minor changes).
Once you've completed and confirmed your AWStats is working this section should help you get JAWStats up and running successfully.
Getting JAWStats
For this you'll want to go to the JAWStats download page located a http://www.jawstats.com/download.
Alternatively, you can download the current version (at the time of writing) from the command line:
wget http://www.jawstats.com/src/jawstats0.6beta.tar.gz
If you've downloaded it using the command line before you untar it you'll want to have it inside the directory (because it'll untar without it's own container file).
So for example:
mkdir ~/jawstats/ mv ~/jawstats0.6beta.tar.gz ~/jawstats/ cd ~/jawstats/ tar xfzv jawstats0.6beta.tar.gz rm -f ./jawstats0.6beta.tar.gz (just cleaning up the archive)
You should now have a directory:
/home/yourusername/jawstats/
Who's contents should look like this:
clsAWStats.php config.dist.php index.php js readme.txt swf themes xml_history.php xml_pages.php xml_stats.php xml_update.php
These are the main application files for JAWStats.
Installation
The installation of JAWStats is very simple. If you've followed the instructions for the AWStats installation above and have it working then we will only make a few simple changes and you'll be up and running!
Moving the files into place
In the section Setting up the Domain Name above we copied some AWStats files into the folder we'd using to view/access AWStats, as shown below:
cp -r ~/awstats/wwwroot/{icon,css,js} ~/domainname.com/statistics
For JAWStats we won't actually need those. Instead we'll be using the JAWStats files you just downloaded and extracted.
So lets clear out the AWStats files in our domain folder and copy our new JAWStats files into place:
rm -fr ~/domainname.com/statistics/* cp -R ~/jawstats/* ~/domainname.com/statistics/
JAWStats configuration
Now that all the files are in place we've got to do a quick bit of configuring to let JAWStats know where to find AWStats and the files it will need to display your data.
First, lets move into the directory.
cd ~/domainname.com/statistics/
You'll see a few files in here, but you can ignore everything but a file called config.dist.php.
This is the file that will become your configuration, lets rename it:
cp ./config.dist.php ./config.php
and open the file for editing
vi config.php
What you see might look confusing, but we only need to worry about the site configuration section(s) which look like this:
// individual site configuration $aConfig["site1"] = array( "statspath" => "/path/to/data/", "updatepath" => "/path/to/awstats.pl/", "siteurl" => "http://www.my-1st-domain.com", "theme" => "default", "fadespeed" => 250, "password" => "my-1st-password", "includes" => "" );
The line we'll be editing are:
$aConfig["site1"] = array( "statspath" => "/path/to/data/", "updatepath" => "/path/to/awstats.pl/", "siteurl" => "http://www.my-1st-domain.com", "password" => "my-1st-password",
And the changes are actually pretty straight froward. Using the AWStats configuration as an example we'll end up with something like this:
// individual site configuration $aConfig["domainname.com"] = array( "statspath" => "/home/yourusername/awstats/data/", "updatepath" => "/home/yourusername/awstats/cgi-bin/", "siteurl" => "http://www.domainname.com", "theme" => "default", "fadespeed" => 250, "password" => "mynewsupersecretpassword", "includes" => "" );
domainname.com is the website domain name you used in naming your awstats.domainname.com.conf file.
statspath is the DirData setting you added to the awstats.domainname.com.conf file
updatepath is the location of the cgi-bin which you moved in the Changing the Directory Structure section.
siteurl is simply the domain name which JAWStats will display in heading making it easy to know what it is you're looking at.
password is pretty self explanatory but it's a good idea to change this and if you leave $bConfigUpdateSites option in the section above in it's default state (true) you'll be asked to input the password you configure here to run an update on the sites stats (an handy feature for the stats obsessed!).
Wrap-up and CRON Script changes
That covers basic configuration. You'll notice the JAWStats file has (by default) 2 example site sections. You can add additional sites to the configuration as above, as long as each site has a matching (and working!) AWStats configuration you can quickly and easily switch between viewing statistics for each domain from the JAWStats interface.
Testing and CRON setup with JAWStats is pretty much the same. But you'll want to change the line you'll be using for you CRON script.
The AWStats example looked like this:
0 3 * * * /usr/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
However JAWStats doesn't need AWStats to do as much work, we only need to generate the data files. So instead you can use something like this:
0 * * * * perl /home/yourusername/awstats/tools/awstats_updateall.pl now -configdir=/home/yourusername/awstats/cgi-bin/ -awstatsprog=/home/yourusername/awstats/cgi-bin/awstats.pl
Notice we've skipped the awstats_buildstaticpages.pl because we'll be using JAWStats to provide much nicer looking pages. I also use the awstats_updateall.pl which is under the AWStats tools directory. This script is will process all the files in your -configdir automatically (excluding the awstats.model.conf file). So if you have more then a single domain setup you can use a single CRON script and process them all rather then installing one AWStats CRON job for every domain.
If everything goes right you should now have an attractive and easy to use interface setup to use your AWStats datafiles. Enjoy!
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.
- AWStats Configuration - List of configuration directives with instructions. Easier on the eyes than what's in the config files.


