Setting up awstats with apache 2 & geoip on debian-ubuntu

Awstats is a web log analyzer. It gives really useful statistics about traffic on your web sites.This log analyzer works as aCGI or from command line and shows you all possible information your log contains, in few graphical web Awstats Monthly Viewpages.

yesterday, it took me many hour to configure it on my server, I took help from many blogs to complete it.

Hope this can help someone.

1. Installing Awstats:

ab@web1:~$ sudo apt-get install awstats

This command will install awstats.Now we have to configure Apache.

2. Configuring Apache2:

Now make the following changes inawstats.conf file.

ab@web1:~$ sudo vi /etc/apache2/awstats.conf

Alias /awstatsclasses “/usr/share/awstats/lib/”
Alias /awstats-icon/ “/usr/share/awstats/icon/”
Alias /awstatscss “/usr/share/doc/awstats/examples/css”
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

After, Making these changes, we have to include this file (/etc/apache2/awstats.conf) in to our apache.conf file, so we can access it over http.

ab@web1:~$ sudo vi /etc/apache2/apache2.conf

Include /etc/apache2/awstats.conf

Now, reload the apache.

ab@web1:~$  sudo /etc/init.d/apache2 reload

Now you can try to open but you will get this error:  Error: SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats.

That means we have to configure Awstats.

3. Configuring Awstats:

By default awstats provides a default configuration file named /etc/awstats/awstats.conf. Copy this file to /etc/awstats/

~$sudo cp /etc/awstats/awstats.conf /etc/awstats/

and edit the file:

~$sudo vi /etc/awstats/

and check for the following lines and edit those for your needs:


This is all setted up, now you need to generate the first stats.

4. Generating the First Stats:

in order to generate the first stats, you need to call the script as root using the following command line:

~:$sudo -u www-data /usr/bin/perl /usr/lib/cgi-bin/ -update

After finishing this you can try to open this will show you the stats.

Now for automatic update the stats you need to put the following command in your cron.

0 2 * * * www-data [ -x /usr/lib/cgi-bin/ -a -f /etc/awstats/awstats.conf -a -r /var/log/apache/access.log ] && /usr/lib/cgi-bin/ -update >/dev/null

GeoIP Information for AWStats

Improve country and city location information in your web analytics reports

Awstats showing country info

AWStats offers three different ways to provide Country level information about visitors (“hosts”) connecting to your site. By default, the host domain extension is used if you have performed reverse DNS look-up. While this results in human readable host names as well, reverse DNS lookup is time consuming. Alternatively, GeoIP plugins can be used. They match the host IP with a database of IP allocations which is already installed locally on your computer, significantly reducing the time needed to match a host to a location. There are two country level GeoIP databases available. AGeo::IPFree Perl module is available, but it does not appear that the database is being maintained. The better solution is MaxMind’s Geo::IP GeoLite Country open source version, said to be 97% accurate.

Download the current GeoLite Country, GeoLite City and Organization (AS Numbers)databases

Move data files to directory and unzip.

mv GeoIP.dat.gz /usr/local/share/GeoIP/
gunzip /usr/local/share/GeoIP/GeoIP.dat.gz
mv GeoLiteCity.dat.gz /usr/local/share/GeoIP/
gunzip /usr/local/share/GeoIP/GeoLiteCity.dat.gz
mv GeoIPASNum.dat.gz /usr/local/share/GeoIP/
gunzip /usr/local/share/GeoIP/GeoIPASNum.dat.gz
Install the GeoIP program.

1. wget
tar -xvzf GeoIP-1.4.5.tar.gz
cd GeoIP-1.4.5
make check
sudo make install

tar -xvzf Geo-IP-1.35.tar.gz
cd Geo-IP-1.35
perl Makefile.PL LIBS=’-L/usr/local/lib’
make test
sudo make install

Update your awstats.mysite.conf configuration file

Look for the following geoip LoadPlugin options in your AWStats configuration file. Update them with the full path to each of the two database files.

LoadPlugin=”geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat”
LoadPlugin=”geoip_org_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoIPASNum.dat”

Well, It’s done and now you can check the stats with country info.



$ locate GeoIP.dat


perl -MCPAN -e ‘install “Geo::IP”‘

perl -MCPAN -e ‘install “Geo::IP::PurePerl”‘


# LoadPlugin=”geoip GEOIP_STANDARD /pathto/GeoIP.dat”
LoadPlugin=”geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat”



LoadPlugin=”geoip GEOIP_STANDARD /pathto/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /pathto/GeoIPCity.dat”
LoadPlugin=”geoip GEOIP_STANDARD /home/awstats/awstats/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /home/yourname/awstats/GeoIPCity.dat”



1. 下载纯真版IP数据库,解压缩后,只使用QQWry.dat
2. 下载
3. 下载分析QQWry.dat的脚本
4. 把以上文件都放在cgi-bin/plugins下
5. 修改,把./QQWry.dat改为${DIR}/plugins/QQWry.Dat
6. 修改common.conf,加入LoadPlugin=”qqhostinfo”



如果在没有的虚拟主机上安装,由于没有管理员权限,所以,正常的安装过程在make install的时候会报错的。所以,可以这样:

$ make Makefile.PL PREFIX=/home/yourname/awstats/lib # 这样可以把最后的安装都放在这个目录里
$ make
$ make install

另外,如果对中文搜索引擎统计有更高需求的话,可以使用车东的TOP 8 Chinese local search engines。这东西是将近一年前的,适用于AWStats-6.6,对于6.7来说不太合适。我做了一个6.7的,可以对search_engines.pm打patch。不管在本地,还是在DH主机的shell里,可以




       ppm install Geo::IP::PurePerl
       ppm install Geography::Countries
       ppm install IP::Country 
       ppm install Geo-IPfree
       ppm install  Net-Xwhois 



GeoIP.dat,、、QQWry.dat3 打包CSDN下载:



        开启 GeoIP 反查模块
       LoadPlugin=”geoip GEOIP_STANDARD C:/Perl/lib/GeoIP.dat”
       开启 IP 反查的外挂
       # 开启 decodeutfkeys 外挂,解决“用以搜索的关键词”乱码
       LoadPlugin=”timezone +8″好了,所以的设置都弄好了,awstats已经能够很好的工作了。
       # Plugin: qqhostinfo,显示访问者地区,下面的语句需要手工添加。

       # 开启HostInfo,这个是qqhostinfo插件的前提


*  上面插件加载地址按需修改 


It may not be able to give the same level of detail as a commercial package such as Urchin, but it provides more than enough detail for most purposes.
On Ubuntu you can install awstats via apt:
apt-get install awstats
This will install the base package however, if you want to lever its full power you will need to install a couple of extra Perl modules.
apt-get install libnet-ip-perl
If you would like to see which countries your visitors are based in then you should look at one of the IP to Country plugins which will give you a Geo IP lookup.
You can choose between either geoipfree or GeoIp.
Other useful plugins are:

  • Plugin: HostInfo – which gives you a popup whois window
  • Plugin: IPv6 – adds IPv6 support
  • Plugin: Tooltips – confused by all the information? This will take away the mystery :)

On rpm-based system there is a handy little perl script that walks you through the initial configuration. On Ubuntu you have to do it by hand, however most of the configuration is self-explanatory.
Simply copy the provided sample config to a new config file:
cp awstats.conf awstats.yoursite.tld.conf
NB: You will need a separate configuration file for each vhost you wish to examine.
Edit the conf file to match your site’s setup. Important things to pay attention to are any domain aliases, the location of the log files and any IPs you wish to ignore (eg. your own)
You can also decide which optional plugins you want to load. Simply add a line to invoke each one:

geoipfree requires an extra perl module. On ubuntu the package is called libgeo-ipfree-perl
You are almost ready!
You now need to configure Apache to allow access to your awstats pages.
Rather than messing about with my main Apache config file I found it neater to place the awstats specific information in an external file called awstats.conf:

Options None
AllowOverride None
Order allow,deny
Allow from all

Alias /awstatsicons/ /usr/share/awstats/icon/
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all

Then use an include directive in your main Apache config (apache2.conf):
Include /etc/apache2/awstats.conf
You then need to add it in to your vhost:
ScriptAlias /whereyouwanttoaccessit/ /usr/lib/cgi-bin/
If you navigate to:


You *should* be able to access your stats.
Of course you’ll need to actually generate the stats first:
/usr/lib/cgi-bin/ -config=yourdomain.tld -update
I would recommend you run this from the command line once to create the first set of stats and then add a cronjob:
crontab -e
0,10,20,30,40,50 * * * * /usr/lib/cgi-bin/ -config=yourdomain.tld -update >/dev/null

This will update your stats every 10 minutes, which means that you’ll only have to update a few lines at a time. If your site is busy this makes sense :)
The last part of the line is important:
By default cron emails the user each time it runs. You really don’t want 6 emails an hour telling you that Awstats has run :)

How to reset awstats

Just delete the files in /var/lib/awtstats (directory defined by DirData parameter)

sudo su - root
cd /var/lib/awstats
rm *


  • you have to be root because for some reason, sudo rm -R awstats/* wouldn’t work.
  • if you get the message Never updated (See 'Build/Update' on awstats_setup.html page) whereas the awstats files are there in /var/lib/awtstats, it’s probably a permission problem on this folder.

CC BY-NC-SA 4.0 Setting up awstats with apache 2 & geoip on debian-ubuntu by 桔子小窝 is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.