This works for Ubuntu, Debian and CentOS distributions. You need a valid license key from MaxMind. This is available as a subscription at a nominal fee.

If you have installed GeoIP successfully, you should have the geoipupdate program. If you don’t, you need the run the following.

Install over Ubuntu or Debian:

[code lang=“bash”]sudo apt-get install geoip-bin geoip-database libgeoip-dev[/code]

Install over CentOS:

[code lang=“bash”]sudo yum install re2c geoip geoip-data geoip-devel[/code]

Both libgeoip-dev and geoip-devel are required for compiling PHP’s GeoIP.

Once you run geoipupdate the first time, it tells you about a missing GeoIP file.

[code lang=“bash”]root@gladlycode:~# geoipupdate

Error opening GeoIP Configuration file /etc/GeoIP.conf[/code]

Now you copy over from the default file:

[code lang=“bash”]mv /etc/GeoIP.conf.default /etc/GeoIP.conf[/code]

If you now run geoipupdate, you get the following:

MD5 Digest of installed database is f5c2f7eed9331dcaa99b7a6b4633b684

Invalid UserID

Log into your MaxMind account if you are already a paying customer and get the API keys.

Edit your /etc/GeoIP.conf file to add in the license key. It should look something like the following:

[code lang=“bash”]LicenseKey

Enter your User ID here


Enter the Product ID(s) of the database(s) you would like to update

By default 106 (MaxMind GeoIP Country) is listed below

ProductIds 106[/code]

And you run geoipupdate again:

[code lang=“bash”]root@gladlycode:~# geoipupdate

MD5 Digest of installed database is f5c2f7eed9331dcaa99b7a6b4633b684

Updating /usr/share/GeoIP/GeoIP.dat

Updated database[/code]

Great success. And you will want to automate these updates. To do so, add it to cron job.

[code lang=“bash”]crontab -e[/code]

Add the following line:

[code lang=“bash”]0 5 * * * /usr/bin/geoipupdate[/code]

This will automatically fetch updates for you.

comments powered by Disqus