Teej
11-05-2006, 07:55 AM
Download, check and extract the latest AWStats package (http://sourceforge.net/projects/awstats/):
cd ~/downloads
wget http://kent.dl.sourceforge.net/sourceforge/awstats/awstats-6.5.tar.gz
tar -tf awstats-6.5.tar.gz
tar -xzvf awstats-6.5.tar.gz -C /opt/
Note that I install all optional packages in /opt/ rather than allowing them to spread all over the system. I then create symbolic links in the locations where other packages might expect them. This way I can easily see all the add-ons installed whilst not having to mess about with the configuration of other packages that rely on them being in a specific location.
I also create version-independent symbolic links so I can upgrade and/or run multiple versions of the same package in parallel.
ln -s /opt/awstats-6.5/ /opt/awstats
ln -s /opt/awstats-6.5/ /usr/local/awstats
We can't usefully run the AWStats configuration script (/opt/awstats/tools/awstats_configure.pl) so we must manually customise the configuration files to reflect the Plesk configuration differences from a standard Apache httpd 2.0 configuration.
Plesk modifies the httpd.conf sequence to deal with its own per-domain, sub-domain, and the user's additional requirements. The sequence is:
/etc/init.d/httpd
/etc/sysconfig/httpd
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf (on my VPS: zz0101_psa_httpd.conf)
/var/www/vhosts/<domain01>/conf/httpd.include
/var/www/vhosts/<domain01>/conf/vhost.conf
/var/www/vhosts/<domain01>/subdomains/<subdomain01>/conf/httpd.include
/var/www/vhosts/<domain01>/subdomains/<subdomain01>/conf/vhost.conf
/var/www/vhosts/<domain01>/subdomains/<subdomain02>/conf/httpd.include
/var/www/vhosts/<domain01>/subdomains/<subdomain02>/conf/vhost.conf
/var/www/vhosts/<domain02>/conf/httpd.include
/var/www/vhosts/<domain02>/conf/vhost.conf
/var/www/vhosts/<domain03>/conf/httpd.include
/var/www/vhosts/<domain03>/conf/vhost.conf
You should never edit each domain's httpd.include file because Plesk writes the contents based on what it has in its database - your changes are likely to be destroyed or cause problems for Plesk/httpd. Instead, create a vhost.conf in the same directory (/var/www/vhosts/<domain>/conf/vhost.conf) with the customised settings.
If it doesn't already exist create the vhost.conf file (make sure to do this as user root). Add the AWStats directives:
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/local/awstats/" must reflect your AWStats Installation path.
#
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Note: AWStats requires the LogFormat be combined. Plesk, however, sets the log-file format to plesklog.
This isn't too much of a problem since the formats are almost always identical. combined is defined in /etc/httpd/conf/httpd.conf as:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
In /etc/httpd/conf.d/zz010_psa_httpd.conf Plesk defines plesklog depending on whether the module mod_logio is loaded, as:
<IfModule mod_logio.c>
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
</IfModule>
<IfModule !mod_logio.c>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
</IfModule>
The only difference being the %O in place of %b, which is the number of bytes sent in the HTTP Response. %O counts the Header bytes, %b doesn't. (see: Apache 2.0 Custom Log Formats (http://httpd.apache.org/docs/2.0/mod/mod_log_config.html#formats))
Remember: To have the vhost.conf for a domain/subdomain included in the start-up sequence you must issue this command to have Plesk add it to the sequence (adds an Include directive to the end of the VirtualHost in httpd.include):
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=<domain_name>
(See: Plesk: Customizable httpd.include per domain (http://download1.sw-soft.com/Plesk/Plesk7.1/Doc/html/plesk-7-reloaded-admin/apas02.html))
Now the configuration is complete the configuration files should be reloaded:
/sbin/service httpd reload
Reloading httpd: [ OK ]
Next, the awstats.<domain>.conf file needs creating. The template is /opt/awstats/wwwroot/cgi-bin/awstats.model.conf.
There is a lot of commentary in the model file which we don't really need in the production system so I've removed it in the interests of clarity (Reduces from 59,600 to 5,900 bytes) and use awstats.compact.conf as my standard domain template.
cat /opt/awstats/wwwroot/cgi-bin/awstats.model.conf | grep -v ^# | grep -v ^$ > /opt/awstats/wwwroot/cgi-bin/awstats.compact.conf
Hint: To remove comments and empty lines from any similar configuration file use this command: cat filename | grep -v ^# | grep -v ^$ > filename.compact
We need to create a directory for the per-domain configuration files and another for the AWStats data files:
mkdir /etc/awstats
mkdir /var/lib/awstats
In the next post I'll describe the per-domain settings.
cd ~/downloads
wget http://kent.dl.sourceforge.net/sourceforge/awstats/awstats-6.5.tar.gz
tar -tf awstats-6.5.tar.gz
tar -xzvf awstats-6.5.tar.gz -C /opt/
Note that I install all optional packages in /opt/ rather than allowing them to spread all over the system. I then create symbolic links in the locations where other packages might expect them. This way I can easily see all the add-ons installed whilst not having to mess about with the configuration of other packages that rely on them being in a specific location.
I also create version-independent symbolic links so I can upgrade and/or run multiple versions of the same package in parallel.
ln -s /opt/awstats-6.5/ /opt/awstats
ln -s /opt/awstats-6.5/ /usr/local/awstats
We can't usefully run the AWStats configuration script (/opt/awstats/tools/awstats_configure.pl) so we must manually customise the configuration files to reflect the Plesk configuration differences from a standard Apache httpd 2.0 configuration.
Plesk modifies the httpd.conf sequence to deal with its own per-domain, sub-domain, and the user's additional requirements. The sequence is:
/etc/init.d/httpd
/etc/sysconfig/httpd
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf (on my VPS: zz0101_psa_httpd.conf)
/var/www/vhosts/<domain01>/conf/httpd.include
/var/www/vhosts/<domain01>/conf/vhost.conf
/var/www/vhosts/<domain01>/subdomains/<subdomain01>/conf/httpd.include
/var/www/vhosts/<domain01>/subdomains/<subdomain01>/conf/vhost.conf
/var/www/vhosts/<domain01>/subdomains/<subdomain02>/conf/httpd.include
/var/www/vhosts/<domain01>/subdomains/<subdomain02>/conf/vhost.conf
/var/www/vhosts/<domain02>/conf/httpd.include
/var/www/vhosts/<domain02>/conf/vhost.conf
/var/www/vhosts/<domain03>/conf/httpd.include
/var/www/vhosts/<domain03>/conf/vhost.conf
You should never edit each domain's httpd.include file because Plesk writes the contents based on what it has in its database - your changes are likely to be destroyed or cause problems for Plesk/httpd. Instead, create a vhost.conf in the same directory (/var/www/vhosts/<domain>/conf/vhost.conf) with the customised settings.
If it doesn't already exist create the vhost.conf file (make sure to do this as user root). Add the AWStats directives:
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/local/awstats/" must reflect your AWStats Installation path.
#
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Note: AWStats requires the LogFormat be combined. Plesk, however, sets the log-file format to plesklog.
This isn't too much of a problem since the formats are almost always identical. combined is defined in /etc/httpd/conf/httpd.conf as:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
In /etc/httpd/conf.d/zz010_psa_httpd.conf Plesk defines plesklog depending on whether the module mod_logio is loaded, as:
<IfModule mod_logio.c>
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
</IfModule>
<IfModule !mod_logio.c>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
</IfModule>
The only difference being the %O in place of %b, which is the number of bytes sent in the HTTP Response. %O counts the Header bytes, %b doesn't. (see: Apache 2.0 Custom Log Formats (http://httpd.apache.org/docs/2.0/mod/mod_log_config.html#formats))
Remember: To have the vhost.conf for a domain/subdomain included in the start-up sequence you must issue this command to have Plesk add it to the sequence (adds an Include directive to the end of the VirtualHost in httpd.include):
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=<domain_name>
(See: Plesk: Customizable httpd.include per domain (http://download1.sw-soft.com/Plesk/Plesk7.1/Doc/html/plesk-7-reloaded-admin/apas02.html))
Now the configuration is complete the configuration files should be reloaded:
/sbin/service httpd reload
Reloading httpd: [ OK ]
Next, the awstats.<domain>.conf file needs creating. The template is /opt/awstats/wwwroot/cgi-bin/awstats.model.conf.
There is a lot of commentary in the model file which we don't really need in the production system so I've removed it in the interests of clarity (Reduces from 59,600 to 5,900 bytes) and use awstats.compact.conf as my standard domain template.
cat /opt/awstats/wwwroot/cgi-bin/awstats.model.conf | grep -v ^# | grep -v ^$ > /opt/awstats/wwwroot/cgi-bin/awstats.compact.conf
Hint: To remove comments and empty lines from any similar configuration file use this command: cat filename | grep -v ^# | grep -v ^$ > filename.compact
We need to create a directory for the per-domain configuration files and another for the AWStats data files:
mkdir /etc/awstats
mkdir /var/lib/awstats
In the next post I'll describe the per-domain settings.