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:
sudo apt-get install geoip-bin geoip-database libgeoip-dev
Install over CentOS:
sudo yum install re2c geoip geoip-data geoip-devel
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.
root@gladlycode:~# geoipupdate Error opening GeoIP Configuration file /etc/GeoIP.conf
Now you copy over from the default file:
mv /etc/GeoIP.conf.default /etc/GeoIP.conf
If you now run geoipupdate, you get the following:
MD5 Digest of installed database is f5c2f7eed9331dcaa99b7a6b4633b684
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:
LicenseKey <Your License Key> # Enter your User ID here UserId <Your Numerical User Id> # 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
And you run geoipupdate again:
root@gladlycode:~# geoipupdate MD5 Digest of installed database is f5c2f7eed9331dcaa99b7a6b4633b684 Updating /usr/share/GeoIP/GeoIP.dat Updated database
Great success. And you will want to automate these updates. To do so, add it to cron job.
Add the following line:
0 5 * * * /usr/bin/geoipupdate
This will automatically fetch updates for you.