First let me make it clear I prefer webalizer to awstats; however webalizer is not available in the repositories after CentOS7. It is also worth noting that both webalizer.org and mrunix.net (where webalizer sources/downloads could be manually obtained) appear to be no longer online and there does not appear to be a github source for it either.
Another issue is that webalizer requires, and awstats can use the free geo-ip ‘lite’ country databases from maxmind to resolve ip-addresses to countries; however while still free from December 2019 you must create an account to download them (https://dev.maxmind.com/geoip/geoip2/geolite2/) and we all have far too many internet accounts as it is.
So with webalizer being unavailable and awstats fortunately able to use another free (although out of date) ip lookup database awstats is the logical replacement.
Preparation work
For awstats to use the free ip database you need an additional perl module, you should therefore try to install that first.
perl -MCPAN -e shell install Geo::IPfree
For awstats to produce PDF reports the ‘htmldoc’ package needs to be installed; that unfortunately is also not in the CentOS8 repositories and would need to be installed using snap. Documentation in installing htmldoc using snap is at https://snapcraft.io/install/htmldoc/centos; however I did not install it as snap is a bloody pain to use and chews up a lot of system resources; the only time I installed snap to get a package I immediately uninstalled it all again. Fortunately if you do not need to generate PDF reports that is no issue. Should the ‘htmldoc’ package ever make it to the CentOS8 repositories I will install it from those at that time.
It is also very important to note that awstats expects all httpd log messages to be in a specific format or it will refuse to process the logs. Anywhere you are defining log files you should use
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined CustomLog "logs/access_log" combined
You would normally need to set these in a default installation in /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/ssl.conf; but set anywhere you define log files.
It is also important to note that awstats wants to process only one file, and expects it to be in date order, so if you have seperate access_log and ssl_access_log messages (the default in a CentOS install) you will have issues. What I have done, as I wish to keep seperate files to identify the different traffic for other utilities, is leave those alone but add as an additional entry anywhere that needs logging a new logfile all will share, for example the below line I would have in both the main httpd.conf and ssl.conf files so as well as the unique files all messages from both are also logged to a combined file in the correct LogFormat tagged as ‘combined’.
CustomLog "logs/combined_access_log" combined
This permits the single LogFile name needed by awstats to be used against a file that does contain all the log messages needed.
If your logfiles were not already using the correct format all the existing logfiles cannot be processed by awstats. If you have just configured a new ‘combined_access_log’ as discussed above in the required format restart httpd to start aquiring messages in that file that you can use in later steps.
Installing, configuring, populating
To install awstats it is simple a case of ‘dnf -y install awstats’.
After which there is a bit of editing involved, while it does create a /etc/httpd/conf.d/awstats.conf file all the entries in there refer to /usr/local/awstats but the package files are actually installed in /usr/share/awstats. The best option is to remove everything in that file and replace it with the contents below. The file below is based upon the documentation at https://tecadmin.net/steps-to-configure-awstats-on-centos-and-rhel-system/ but modified to include access to the documentation directory (as being able to browse the documentation is useful) as well as using the latest ‘require ip’ syntax (as ‘allow from’ and ‘require host’ are obsolete and not able to be used without loading compatibility modules).
# # Content of this file, with correct values, can be automatically added to # your Apache server by using the AWStats configure.pl tool. # # If using Windows and Perl ActiveStat, this is to enable Perl script as CGI. #ScriptInterpreterSource registry # # 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 install path. Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/" Alias /awstatscss "/usr/share/awstats/wwwroot/css/" Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/" ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/" Alias /awstatsdoc "/usr/share/doc/awstats/" <Directory /usr/share/doc/> DirectoryIndex index.html Require all granted </Directory> <Directory "/usr/share/awstats/wwwroot"> Options +ExecCGI AllowOverride None Require ip 192.168.1.0/24 </Directory> <IfModule mod_env.c> SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins </IfModule>
You then need to ‘cd /etc/awstats’. You will find a model.conf, awstats.localhost.localdomain.conf, and awstats.HOSTNAME.conf (where HOSTNAME) is the name of your host have been created. Copy any one of them to awstats.your.website.name.conf where your.website.name is your website name, for example if your host is webserver.example.org you need a file named awstats.webserver.example.org.conf; and then open the new file in your favourite editor.
- set the ‘LogFile’ value; if you followed my recomendation of using a combined_access_log above set it to that, otherwise set it to the only one of the files you want to process (masks such as “*access.log” will not work; also logresolvmerge as documented in template file did not work for me)
- set the ‘SiteDomain’ value to match your website name
- set the ‘HostAliases’ values
- set the ‘DNSLookup’ value to ‘0’ unless you want to do lots of dns lookups
- review the comments for ‘EnableLockForUpdate’ and decide if you want to set it to ‘0’
- if using dns lookups set the ‘SkipDNSLookupFor’ list
- you may want to set ip-addr ranges for clients that can browse the results in the ‘AllowAccessFromWebToFollowingIPAddresses’ list; although you are also limiting by ip-address in the conf.d/awstats.conf file above
- set the ‘SkipHosts’ value to avoid reporting on internal hosts that would skew the report values (such as nagios/nrpe or other health checking activity)
- Seach on ‘LoadPlugin=”geoipfree”‘ and uncomment it (if you installed the Geo::IPfree mentioned at the start of this post)
- set ‘UseFramesWhenCGI=0’, browsers such as FireFox will refuse to display any pages presented in frames aas frames are inherently insecure
You should also note the entries for URL alias references (/awstatscss,/awstatsicons etc) throughout the file, initially leave all those as the defaults as they match what is set in the /etc/httpd/conf.d/awstats.conf file; and they must match.
Before you are able to do anything you need to create some initial data. If you have had to change your log message formats after restarting httpd just wait for a while, you need some log messages available before you are able to initialise awstats.
When you have a reasonably large collection of logged messages simply run the command below replacing ‘webserver.example.org’ with your hostname, which is the part between awstats. and .conf in the /etc/awstats directory; the example below would use the config file ‘awstats.webserver.example.org.conf’.
perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=webserver.example.org -update
Keeping the statistics up to date
Installing the package creates a file that will perform updates for all the hosts you have configured in seperate conf files for each host in /etc/awstats. That job is /etc/cron.hourly/awstats.
So once you have all the configuration in the steps above done your data is updated automatically.
You may want to create a report job in /etc/cron.daily or /etc/cron.monthly to produce reports that can be archived in case you need to initialise your collected statistics at some point.
Viewing the statistics with a web browser
I suppose after all that work you actually want to look at some of the statistics. If you use the example /etc/httpd/conf.d/awstats.conf file above you would point your web browser at https://yourhostname/awstats/awstats.pl?config=webserver.example.org where the config value matches the configuration file you used.
If you are used to webalizer output you may find it frustrating to hunt down information in. Some information is also incorrect with default settings although I suppose it is possible to correct it with a lot of manual effort in the configuration file and log format statements. But as webalizer is no longer available awstats is a viable replacement; if a lot harder to get working.
The ability to generate static reports may be useful for archiving, but I have not tested that as they would be most useful in PDF form, which as mentioned above awaits the ‘htmldoc’ package reaching the CentOS8 repos one day.