Setting Up GeoIP Location on Piwik on ServerPilot

Using a combination of ServerPilot and a Vultr server instance is a great solution for a Piwik server for tracking analytics.

After setting up the initial Piwik install here is how you can set up the GeoIP location module set up to enable you to view visitor results from City and Country Location. Piwik can take advantage of Maxminds’ databases to track visitor IP address to City/Country location.

First you need to set up the PHP extension for GeoIP, download the Geo database and confirm it’s location and then auto update the database updates.

PHP Config

Installing GeoIP on PHP 7.1

If the PHO version you are using change the version number – such as 5.6 (if you are using PHP 5.6)

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libgeoip-dev
sudo pecl7.1-sp install geoip-beta

Followed by some PHP config

sudo bash -c "echo extension=geoip.so > /etc/php7.1-sp/conf.d/geoip.ini"
sudo service php7.1-fpm-sp restart

Point ServerPilots PHP Config to the Geo Database

Create a .user.ini file in your apps webroot and add in the path to the database

geoip.custom_directory = "/pathtopiwikinstall/misc"

Piwik Config

Set the Piwik GeoLocation Setting

In Piwik > Settings > System > GeoLocation – select the GeoIP (PECL) selection.

piwik-geo-ip-location

 

MaxMind GeoIP Databases

With the PHP & Piwik configuration complete now what is needed is to use the City databases which link IP addresses to City/Country, there are paid and free options available from Maxmind, download the GeoLite city database  in binary format, rename it GeoIPCity.dat and file in your /misc directory in the Piwik installation.

piwik-maxmind-geo-city-database

Confirm Piwik Can Access Database

This is done by seeing that the Piwik > Settings > System > GeoLocation  settings can see where you are from !

piwik-geo-city-confirm

Set Up Piwik to AutoUpdate the Database

The GeoLite City database is changed each month, Piwik can automatically download and use the latest version also in the Piwik > Settings > System > GeoLocation settings. It’ll prompt you with the correct URL to use.

piwik-auto-update-geo-database

Sources

2 Comments

  1. Warner on September 13, 2017 at 6:43 am

    yet again a great tutorial.

    I am always amazed of the synchronicity between my informational need and the actual content you schedule on your site.

    Having dificulties setting up the WPC in Atom; check

    Wanting to auto update the MaxMinds database for Piwik on SP; check

    I could continue, but instead I just want to say “thank you!” for sharing your knowledge.

    Count on me to show up regularly in your Piwik analytical data.

    • Neil Gowran on September 13, 2017 at 6:56 am

      Thanks for saying – our technical path/plight must be aligned

Leave all Comment