Home | Portfolio | Services | About | Contact

Awstats website statistics on debian installation guide

Monday, 01 October 2007

This guide will show you the basics on how Abludo installed Awstats website statistics on our Debian linux web server. Awstats is a fantastic open source stats package that you can download free from the website. Before we begin, please note that we have installed "sudo" to run commands as root. This is not a standard default configuration on Debian, this is Ubuntu style. So when you see "sudo" you know you have to exectute the command as root, by using "su" (super user) for example.

This being a debian specific guide, you can also use the user-friendly "apt" package manager to fetch and install the program files, as you can with most other software. This should also work for Ubuntu since it's based on Debian, although some of the paths referenced in this guide will vary somewhat. From the command you can use either apt-get or aptitude; from the graphical user interface in x-windows you can also use synaptic. Here is the most basic command to fetch the package automatically:

sudo apt-get awstats

It won't give you any information on where it installed everything, so do a quick search to find the files on your system. The "locate" command in debian is not very powerful, so we recommend upgrading to slocate which is standard on Ubuntu (sudo apt-get slocate). Once you have it, you can run these two commands. The first is to update the database with all the files you currently have on your machine (will take a few minutes), the other is to actually find the file we're looking for. If you just can't use locate for whatever reason, then don't fret, it just might be here: /usr/local/awstats/awstats_configure.pl

locate -u
locate awstats_configure.pl

Now you can go ahead and run the awstats installation wizard. The command to do so and the output is the following:

sudo perl awstats_configure.pl


Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/usr/share/doc/awstats/examples
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ?

You want to answer "no" to that question. Move it to the standard directory as it recommends with this command. Why Debian didn't put in the appropriate location in the first place is a mystery to me!

sudo mv examples /usr/local/awstats

Before running the wizard again, you will need to locate your httpd.conf because it will ask for it. Here is the command in case you can't guess it, and the standard location in case locate still isn't working for you. Finally, the last command is simply how we run the setup wizard again and the output it generates. Pay close attention to how we have answered the questions and answer them the same way.

locate httpd.conf
/etc/apache2/httpd.conf

sudo perl awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.6) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix -----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:Program filesapache groupapacheconfhttpd.conf
Config file path ('none' to skip web server setup):
> /etc/apache2/httpd.conf


  Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '<Directory>' directive
  AWStats directives added to Apache config file.
-----> Need to create a new config file ?


Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
-----> Define config file name to create


What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:

> www.mywebsite.com
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>
-----> Create config file '/etc/awstats/awstats.www.mywebsite.com.conf'
Error: Failed to open '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' for read.


We got a little bit further, but we're still having problems. It can't find the file it's looking for because it is in a zipped file called "awstats.model.conf.gz". Here is how you get to it, unzip it and move it to the proper location (again, why it was zipped makes no sense, apt didn't do a very good job in this case, but it usually does):

cd /usr/local/awstats
sudo gunzip awstats.model.conf.gz
sudo mkdir wwwroot
cd wwwroot
sudo mkdir cgi-bin
cd ..
sudo mv awstats.model.conf ./wwwroot/cgi-bin/awstats.model.conf


Yes, it's time to run this tired old command again.  Here is the command (if you don't know it by heart) and the remaining output (see above for the first part).

sudo perl awstats_configure.pl


[...]

-----> Create config file '/etc/awstats/awstats.www.mywebsite.com.conf'
Config file /etc/awstats/awstats.www.mywebsite.com.conf created.


-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.mywebsite.com


Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now


Press ENTER to continue...


A SIMPLE config file has been created: /etc/awstats/awstats.www.mywebiste.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.mywebsite.com' with command:


> perl awstats.pl -update -config=www.mywebsite.com
You can also read your statistics for 'www.mywebsite.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.mywebsite.com


Press ENTER to finish...

You might have noticed that it said "can't create a cron job". This is because awstats needs to be run every day if it's going to be kept up to date, it will not update itself automatically without a job scheduled in cron. Explaining how to create a cron job is beyond the scope of this guide. But check the list of tutorials on the main page to see if we have created one since this writing. We will however show you how to configure your apache web server the correct way. But before we can even do that, there is another file we consider to be misplaced. Run this command to move it to the correct location:

cd /usr/lib/cgi-bin
sudo mv awstats.pl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl

Then using your favorite editor in root mode, change thesee lines in apache2.conf, without this change image and stylesheet references will be broken. If you don't have a favorite editor, you can use "vim". The first line is the command, the next ones are for the line to change in the web server's config file:

sudo vim /etc/apache2/apache2.conf

Change from Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
to Alias /awstatscss "/usr/share/awstats/css/"
Also change Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
to Alias /awstatsicons "/usr/share/awstats/icon/"

We can finally attempt to actually compile some stats. To do this run the following command. The first error is because it's tries to compile website stats for the "model file", you can safely ignore this error.

sudo perl /usr/local/awstats/awstats_updateall.pl now

Error: SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats.Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=default -configdir="/etc/awstats"' to update config default Setup ('/etc/awstats/awstats.conf' file, web server or permissions) may be wrong. Check config file, permissions and AWStats documentation (in 'docs' directory).
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.mywebsite.com -configdir="/etc/awstats"' to update config www.mywebsite.com Update for config "/etc/awstats/awstats.www.mywebsite.com.conf" With data in log file "/var/log/httpd/mylog.log"... Error: Couldn't open server log file "/var/log/httpd/mylog.log" : No such file or directory
Setup ('/etc/awstats/awstats.www.mywebsite.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

The second error (shown above) cannot be ignored however. It can't find the web server's log file for the website! There are two problems here, firstly we didn't tell awstats where to find the log file and we didn't tell apache to create one. To fix the first problem, edit your config file and change the line where the log file is specified:

vim /etc/awstats/awstats.www.mywebsite.com.conf
LogFile="/var/log/apache2/mywebsite.access.log"

Once again how to configure a website in Apache is beyong the scope of this tutorial. We have to assume that your website is already setup as a virtual host. That being the case, you should know where to add these lines in your apache configuration file.

ErrorLog /var/log/apache2/mywebsite.error.log
CustomLog /var/log/apache2/mywebsite.access.log combined

As you already know, any changes to apache's configuration requires a reload

sudo /etc/init.d/apache2 reload

Now give your website at least one hit so that there is something in the log file. Then you can run this command again and everything should work. 

sudo perl /usr/local/awstats/awstats_updateall.pl now

I sincerely hope this tutorial was useful. If you believe we have made a mistake somewhere or the document is incomplete, please contact us.

 

 

 

 



  
 
[ Home | Services | Portfolio | About | Other websites | Contact ]
© Copyright  2007 Abludo