Configuring AWStats – Multiple Domains Hosted On The Same Server
-
This howto assumes:
- You are the owner of your domain
- You are the owner of your system
- You are running an official copy of Centos 5.x or 6.x and not a datacenter clone/image, cPanel or other Centos derivitive
- You have SELinux enabled.
The purpose of this particular setup is to give a stats link to your customers or for your own sites that will show the actual stats as recorded by the Apache httpd log files so you or your customers can contrast and compare with Google Analytics stats.
Applicable to Centos Versions:
- Centos 5.x
- Centos 6.x
Requirements
- Administrative control over your domain and DNS.
- Root access to an official current Centos system.
- Apache httpd configured properly with the domain you want to track with AWStats.
Doing the Work
In this howto we will assume: you are root, you own example.com and have administrative access to create the subdomain stats.example.com.
- Installing the EPEL software repository, AWStats and optional components for Geo tracking:
- After successful install of the above software we will make a copy of the default AWStats config that we can use over and over:
- Next we create the directories for the new subdomain stats.example.com. For security purposes the default Apache httpd docroot in Centos is /var/www/ :
- Next we copy the AWStats program files to our newly created stats.example.com/cgi-bin directory:
- Next let’s alter the Apache httpd conf file and add an entry for our new subdomain:
- Next we’ll edit /etc/httpd/conf.d/awstats.conf to include information about our new subdomain at /var/www/stats.example.com:
- Now let’s edit the awstats.stats.example.com.conf we created in Step 2:
- Next let’s restart Apache httpd so our changes take effect:
- Next we’ll call the AWStats perl script to automatically update our stats right now:
- Finally, to update our stats automatically every hour via cron we do the following:
- We can also use htpasswd to secure the directory from prying eyes:
Click the EPEL link for more verbose instructions or give this command: su -c "http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm" Then issue this command: yum --enablerepo=epel install awstats GeoIP-data perl-Geo-IPSince there is no Centos package for the GeoLiteCity.dat you can get the single file from MaxMind as well as updated GeoIP.dat files here:
http://www.maxmind.com/app/geolitecountry http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz http://www.maxmind.com/app/geolitecity http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzIf you choose to use only the MaxMind files directly, you can put them in /var/www/GeoIP as follows: sudo mkdir /var/www/GeoIP; cd /var/www/GeoIP sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz sudo gunzip GeoIP.dat.gz GeoLiteCity.dat.gz
Copy default conf so we always have a clean starting point if something goes wrong. cp /etc/awstats/awstats.model.conf /etc/awstats/awstats.model.conf.orig Make another copy for our example site. cp /etc/awstats/awstats.model.conf.orig /etc/awstats/awstats.stats.example.com.conf
mkdir /var/www/stats.example.com && mkdir /var/www/stats.example.com/cgi-bin
cd /usr/share/awstats/wwwroot/ && cp -R * /var/www/stats.example.com/ (For this example we're using: awstats-6.95-1.el5)
vi /etc/httpd/conf/httpd.conf add this information at the bottom in the vhosts section or in /etc/httpd.conf.d/vhosts.conf either will work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28You should already have a domain configured that you'd like to track the stats of like this: <VirtualHost *:80> ServerAdmin admin@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com ScriptAlias /cgi-bin/ /var/www/example.com/cgi-bin/ CustomLog logs/example.com_access_log combined ErrorLog logs/example.com_error_log </VirtualHost> We'll be adding this subdomain to track the above domains stats: <VirtualHost *:80> ServerAdmin admin@example.com ServerName stats.example.com DocumentRoot /var/www/stats.example.com ScriptAlias /cgi-bin/ /var/www/stats.example.com/cgi-bin/ CustomLog logs/example.com.stats_access_log combined ErrorLog logs/example.com.stats_error_log ## AWstats ## Alias /classes "/var/www/stats.example.com/classes/" Alias /css "/var/www/stats.example.com/css/" Alias /icon "/var/www/stats.example.com/icon/" ScriptAlias /awstats/ "/var/www/stats.example.com/cgi-bin/" ## End AWstats ## </VirtualHost>
vi /etc/httpd/conf.d/awstats.conf
1 2 3 4 5 6 7 8 9<Directory "/var/www/stats.example.com"> DirectoryIndex awstats.pl Options ExecCGI Options FollowSymLinks Options None AllowOverride None Order allow,deny Allow from all </Directory>
vi /etc/awstats/awstats.stats.example.com.conf
We will be editing the following lines: 1. LogFile="/var/log/httpd/example.com_access_log" 2. SiteDomain="stats.example.com" 3. HostAliases="stats.example.com" 4. DirData="/var/www/stats.example.com/" 5. LoadPlugin="geoip GEOIP_STANDARD /var/lib/GeoIP/GeoIP.dat" (using the yum install method) 6. LoadPlugin="geoip GEOIP_STANDARD /var/www/GeoIP/GeoIP.dat" (using the MaxMind direct download method) 7. LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/www/GeoIP/GeoLiteCity.dat" (using the MaxMind direct download method) Note: The LogFile directive must be the same as the httpd CustomLog directive for the site we actually want the stats from (example.com).
service httpd restart
perl /var/www/stats.example.com/cgi-bin/awstats.pl -config=stats.example.com -update
cd /etc/cron.hourly && vi 01awstats Add this line, save and exit: perl /var/www/stats.example.com/cgi-bin/awstats.pl -config=stats.example.com -update > /dev/null 2>&1 chmod 755 01awstats service crond restart
We'll be doing this work as root in the directory: /var/www/stats.example.com
(In the vi editor use i for insert text, esc + :wq to write and quit vi)
htpasswd -s .htpasswds joe
New password: (This is the user Joe's password to access the stats.)
Re-type new password:
Adding password for user joe
Let's Check to see the password was actually added as expected:
vi .htpasswds
joe:{SHA}9Q+DCACuf4OZs8b0E8eR5j1aIVU=
vi /etc/httpd/conf/httpd.conf
Add this to the virtualhost entry for stats.example.com:
1
2
3
4
5
6
7
8
<Directory "/var/www/stats.example.com">
AuthName "Restricted Area"
AuthType Basic
AuthBasicProvider file
AuthUserFile /var/www/stats.example.com/.htpasswds
AuthGroupFile /dev/null
require valid-user
</Directory>
Now, try hitting your site at: http://stats.example.com You should be prompted for a username and password for your user.
If it does not work, try double checking the steps or join #centoshelp or #httpd on Freenode for further assistance.
Troubleshooting
How to test
- Testing your configuration:
- If this does not work for you, please go through the howto more slowly and double check every setting as well as your Apache httpd error logs:
- If you do not see the GeoIP data, but the rest of AWStats works, check the SELinux file contexts for the GeoIP files:
You should now be able to go to: http://stats.example.com/cgi-bin/awstats.pl and see your sites stats.
Common mistakes are: Typos, file permissions, file ownership, improper or conflicting Apache httpd Options directives or other Apache httpd config errors.
ls -alsZ /var/lib/GeoIP/ incorrect SElinux context --> -rw-r--r-- root root system_u:object_r:var_lib_t GeoIP.dat incorrect SElinux context --> -rw-r--r-- root root system_u:object_r:var_lib_t GeoLiteCity.dat sudo chcon -t httpd_sys_content_t /var/lib/GeoIP/GeoIP.dat sudo chcon -t httpd_sys_content_t /var/lib/GeoIP/GeoLiteCity.dat ls -alsZ /var/lib/GeoIP/ correct SElinux context --> -rw-r--r-- root root system_u:object_r:httpd_sys_content_t GeoIP.dat correct SElinux context --> -rw-r--r-- root root system_u:object_r:httpd_sys_content_t GeoLiteCity.dat You should be able to see country/city GeoIP data now if you refresh the page.
Common problems and fixes
Describe common problems here, including links to known common problems if located on another site
More Information
Any additional information or notes.
Disclaimer
We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #centoshelp on irc.freenode.net


