AWStats is a free and open-source log analyzer and analytics reporting tool that generates advanced server statistics. It supports web, streaming, ftp or mail logs. It can be used from the command line or from the CGI interface and shows you all possible information your log contains in HTML reports with tables and bar graph. It supports most major web server log file formats including Apache, WebStar, IIS and many other common web server log formats.
Install AWStats on Ubuntu
AWStats requires Perl to run, your Perl version must be at least 5.00503 (or higher) to use AWStats 6.x or higher. To check the current version of Perl installed on your system use the following command:
$ perl -v
Now you can go to the AWStats download page and download the latest version using wget and decompress it:
$ wget http://prdownloads.sourceforge.net/awstats/awstats-7.3.tar.gz $ tar zxvf awstats-7.3.tar.gz $ cd awstats-7.3
Afterward in a folder that is accessible via Apache (by default in/var/www/html) move the icon folder from the wwwroot folder there and make sure it is readable by the www-data user/group:
$ cd awstats-7.3/wwwroot/ $ sudo cp -r icon/ /var/www/html/awstats/ $ sudo chown www-data:www-data -R /var/www/html/icon/
Next, you will need to make sure the CGI support is enabled in Apache using the following command:
$ sudo a2enmod cgi
If you get the message:
You can proceed with the installation otherwise you will get a message to also reload apache configuration like this:
Now move the content of the cgi-bin folder to the cgi-bin folder of your Apache installation, by default this is in /usr/lib/cgi-bin:
$ mv cgi-bin awstats $ sudo chown www-data:www-data -R awstats $ sudo mv awstats /usr/lib/cgi-bin
Configuring a website
For each domain or website you wish to view statistics you need to create a configuration file. To do this go in the cgi-bin directory and copy the model config file in a file with the name of your domain or website like this:
$ cd /usr/lib/cgi-bin/awstats $ cp awstats.model.conf awstats.linoxide.conf
Next with your favorite text editor open the new config file and at a minimum change the following directives:
LogFile="/var/log/apache2/access.log"
Change to Apache log file, by default it's /var/log/apache2/access.log
SiteDomain="www.example.com"
Change to the website domain name
AllowToUpdateStatsFromBrowser=1
When this parameter is set to 1, AWStats adds a button on report page to allow to "update" statistics from a web browser
The configure file contains detail explanation for every directive, you might one to check them out if you think you need more info or advanced settings.
Now run the following command to create your stats:
$ /usr/bin/perl /usr/lib/cgi-bin/awstats/awstats.pl -config=linoxide -update
Now you can access your stats at the address http://IP_ADDRESS_OF_YOUR_SERVER/cgi-bin/awstats/awstats.pl?config=CONFIG_NAME.
It will show you a result page like this:
Add a cronjob (optional)
You can add a cron job to run every day so the stats get updated and it will also save you time since running the process manually can take a lot of time if you don't do it daily. You will need to open /etc/crontab in your favorite text editor and add the following line:
00 05 * * * root /usr/bin/perl /usr/lib/cgi-bin/awstats/awstats.pl -config=linoxide -update > /dev/null
This will make the stats update every day at 5am
Protect stats with a username and password (optional)
You can protect your stats with a username and password by adding a .htaccess file in your /usr/lib/cgi-bin/awstats. First you will need to create a password file for your apache installation if you don't have one like this:
$ sudo htpasswd -cm /etc/apache2/passwd linoxide
This will create /etc/apache2/passwd with the username linoxide and the password you provide at the prompt. Then create a .htaccess file in /usr/lib/cgi-bin/awstats with an editor like vim:
$ vim /usr/lib/cgi-bin/awstats/.htaccess
And write the following:
AuthType Basic AuthName "Web Stats" AuthBasicProvider file AuthUserFile /etc/apache2/passwd Require valid-user
This summarizes the installation and configuration of AWStats, one of the best web analytics programs.
Hi
when i follow this i end up whit
Not Found
The requested URL /cgi-bin/awstats/awstats.pl was not found on this server.
I have follow the step but end up whit this. What can be wrong?
Is cgi enabled on your apache ?
Try:
# a2enmod cgi
# service apache2 restart
After setting up the authentication, when I access the stats via a browser, it doesn't prompt me for a password. It just displays this in the browser:
Error: Access to statistics is only allowed from an authenticated session to authenticated users.
Setup ('/etc/awstats/awstats.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).