Posts Tagged Apache
Awstats installation on Red Hat 5.3
Posted by Enrico Aillaud in Unix on September 7, 2009
System requirements:
- A Web Server which must have access to log file had to analyse
- PERL
Steps for installing awstats
- Download the latest stable awstat source code (tar.gz) from:
http://sourceforge.net/projects/awstats/files/
and save it in a folder (i.e. /home/awstats)
- Go in the /home/awstat folder and uncompress the tar.gz file with the following command:
#tar xvf awstats-6.9.tar.gz
- After the decompression move the folder awstats-version in /var/www/html folder with the command:
#mv awstats-version /var/www/html/awstats
- go in the var/www/html/awstats/tools folder and type the following command:
#perl awstats_configure.pl
- Setup steps (the installation will ask for the following directives):
- Do you want to continue setup from this standard directory [yN]?
Type y and press enter to install in the /var/www/html folder - Enter full config file path of your web server.
Type none and press enter - Do you want me to build a new AWStats config/profile file [y/N]
Type y and press enter - What is the name of your web site or profile analysis?
Type the name of the website you want to analyze (ServerName) and press enter - In which directory do you plan to store your config file(s)?
Press enter to use the default one (etc/awstats) - Press enter until you return to shell prompt
- Do you want to continue setup from this standard directory [yN]?
- Create a folder in which store the log file you want to analyze:
#mkdir /etc/awstats/log_servername
- Copy the log file from the server in which are stored the apache access_log:
#scp root@ip_remote_server:/folderInWhichIsStoredAccessLog /etc/awstats/log
(i.e. #scp root@ip-remote-server:/var/log/apache2/access_log /etc/awstats/log)
- The system will ask for a password; insert the root password of the remote host.
- Edit the config file in /etc/awstats (in this case we create the mysite.conf file) with vi:
vi mysite.conf
- Go in the LogFile option and edit it to setup the right logfile that awstats has to analyze:
LogFile = “/etc/awstats/access_log” - Create the folder /var/lib/awstats
#mkdir /var/lib/awstats - Set the permissions in the folders created for apache:
#chown -R apache.apache /var/lib/awstats
#chown -R apache.apache /etc/awstats
#chown -R apache.apache /var/www/html/awstats
(If SELinux activated execute the following 2 commands)
#chcon -R -h -t httpd_sys_content_t /var/www/html/awstats/
#chcon -R -h -t httpd_sys_content_t /var/lib/awstats/ - go in /var/www/html/awstats/wwwroot/cgi-bin/ and type
#perl awstats.pl -config=mysite-update - restart apache:
#service httpd restart - Access from the browser the awstats statistics typing in the address bar:
localhost/awstats/awstats.pl?config=mysite
Notes for old log file:
A fresh awstats installation will not provide full statistics history but there is a way thank to which users could set up awstats to allow a full history statistics (previous log files must be available)
How load previous log file
(Usually previous log files are available in a compress format; in this case for the remote-host we suppose to have a bz2 file extension for old files)
- Copy the access_log.bz2 from the remote host to the local host running the command:
#scp root@remote-server:/var/log/apache2/access_log-*.bz2 /etc/awstats/log - Go in the following folder:
#cd /var/www/html/awstats/tools - Type:
#perl logresolvemerge.pl /folder/access_log-*.* > /folder/access_log - Run the command to update the log file awstats use to make the statistics:
cd /var/www/html/awstats/wwwroot/cgi-bin/
#perl awstats.pl -config=mysite -update
Note for access_log automatic update
In order to have an automatic update of the log file which resides in the remote host we set up a cron job which will update our local log file which resides in the /etc/awstats/log folder.
To accomplish this work we must avoid the password request in ssh setting up the private-public keys security.
Setup SSH without password
- In the localhost run ssh-keygen
- Write the folder in which save the key: /root/.ssh/id_rsa
- Rename id_rsa.pub:
#mv /root/.ssh/id_rsa.pub /root/.ssh/redhat.pub - Run:
scp /root/.ssh/id_rsa root@remote-server:/root/.ssh/ - Access remote server in ssh
- Go in the .ssh folder
#cd /root/.ssh - Type
#cat redhat.pub >> authorized_keys - Run the command:
#service sshd restart
After this setup the connection with the host will be without password
Updating access_log with crontab
#crontab -e
10 9 * * * scp root@remote-host:/var/log/apache2/access_log /etc/awstats/log
11 9 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=mysite –update
How to convert Squid log file to Apache format in order to use Awstats
Posted by Enrico Aillaud in Unix on September 3, 2009
The following guide is the result of a problem I met while trying to analyze old Squid files log with Awstats.
The problem was that the Squid option to write the log format in HTTPD common log file format was disabled and so it was impossible analyzed all previous Squid log files.
So I post this guide to explain how allow Awstats to analyze Squid log format formatted in native mode.
First of all there is a useful free software available at: http://pwebstats.gleeson.net/
The author is Martin Gleeson and he wrote the perl script we need to convert the squid log file.
Save the zipped application file, uncompress it and save the squid2common.pl file in /unix-folder/.
To convert the file simply run the perl script:
perl /unix-folder/squid2common.pl squid-access-log-file
The script will generate two different log files (cache.convert and proxy.convert), the proxy.convert one contains the information Awstats needs to make the reports.
Personally I run the scrip for all old Squid log file and I create a unique access_log file (set up in the awstats.site.com) needed by Awstats to make the statistics with the command:
less cache.convert >> access_log
Finally we must set up the correct LogFormat option on awstats.site.conf in order to allow Awstats to read the squid log file converted:
LogFormat=4
In this way, running the Awstats perl command to update the statistics, we will be able to have in our reports the old squid log files not directly processable by Awstats.
Enrico Aillaud

