FreeBSD Server Administration

« Separate Log Files for Virutal Host | Main | Install ProFTPD »

January 21, 2005

Install Awstats on FreeBSD

Warning: If you are using Awstats 6.2 or earlier version, your server is at great risk, update it now! More information.


I have separated the log files for all virtual hosts, now it's time to install a log analyzer. I used to use offline software, but as the website growing, a faster and more convenient way is a online program.

1. Install Awstats from ports
# cd /usr/ports/www/awstats
# make install
It seems that "make install" only did a download.

2. Config Awstats
Find the file "config.pl", it's under /usr/ports/www/awstats/work/awstats-6.1/tools on my server, run
# ./config.pl
It suggests that the config script should run from /usr/local/awstats, then I copied the whole directory to /usr/local/etc/awstats/
# cp -Rv /usr/ports/www/awstats/work/awstats-6.1/ /usr/local/etc/awstats
(Note: the directory is different for different Awstats versions.)

# chmod +x /usr/local/etc/awstats
(Give Apache permission)

# /usr/local/etc/awstats/tools/configure.pl
This script will ask you a few questions to config Apache, follow the instructions and a config file for this domain will be created. It's better to save the output for reference, many useful information.

3. Modify generated Awstats config file
The config file is generated under /etc/awstats/, named like awstats.www.domain.com.conf
It's necessary to modify this file, the important parameters are:
LogFile="/var/log/domain.com-access_log"
DirData="/var/log/awstats"
(You need to create this directory)

4. Restart Apache
# /usr/local/sbin/apachectl restart

5. Generate stats
This step can be done from the web if you enable AllowToUpdateStatsFromBrowser in the file awstats.www.domain.com.conf.
# /usr/local/etc/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.domain.com
If everything goes well, it will dispaly something like:

Update for config "/etc/awstats/awstats.www.domain.com.conf"
With data in log file "/var/log/domain.com-access_log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 74)
Jumped lines in file: 74
Found 74 already parsed records.
Parsed lines in file: 0
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 3 new qualified records.

6. Test the result
Visit http://www.domain.com/awstats/awstats.pl?config=www.domain.com
Get "permission error"? Check if Apache can read the directory /usr/local/etc/awstats/.

7. Config other domains
Fortunately, you don't have to repeat the config process for all virutal hosts, copy the previous config file and modify the parameters as step 3.

8. Add to cron job
# crontab -e
Insert the following line, Awstats will update at 00:01 everyday.
01 0 * * * /usr/local/etc/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.domain.com
02 0 * * * /usr/local/etc/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.otherdomain.com
(more info about cron job)

Awstats has a command to update all domains, but I wasn't able to run it.
# /usr/local/etc/awstats/tools/awstats_updateall.pl now

Awstats also supports update from the web, I prefer this way - generate the stats only when I need it, add the following line in the file awstats.www.domain.com.conf.

AllowToUpdateStatsFromBrowser=1

9. Protect the Awstats Report
You might want to protect the awstats report, refer to "how to protect a directory under Apache". Note that you must modify Apache configuration file.


Category : Apache

Posted by FreeBSD Newbie at January 21, 2005 07:22 AM

Comments

Nice quick howto, there is a catch though, when you create your config file, that is when you run your /usr/local/etc/awstats/tools/configure.pl, make sure you are in /usr/local/etc/awstats or it will fail to find wwwroot as a base dir.

Posted by FRbsd at April 18, 2006 10:22 PM

There's a problem when testing the result : when I visit www.domain.com/awstats/awstats.pl?config=www.domain.com, I've an internal servor error from apache and the error is :

Insecure dependency in require while running setuid at /usr/local/www/awstats/cgi-bin/awstats.pl line 1469

Posted by Oli at May 5, 2008 05:30 PM

Post a comment



(Optional, will not be shown to the public)

Remember Me?