How do I install GeoIP from MaxMind on Debian 9.

I have used this guide to get started…

https://www.digitalocean.com/community/tutorials/how-to-configure-geoip-pecl-with-piwik-on-an-ubuntu-12-04-vps

I updated the installs for PHP7.0. PECL and GeoIP are installed however MaxMind now requires a login to download their database.

The error I am getting is;

Message: geoip_country_name_by_name(): Required database not available at /var/www/html/thewebsiteapp.com/GeoLite2-Country_20200114/GeoIP.dat.

… which says to me I have a path problem. However, the MaxMind databases are also in .csv or .mmdb format.

Any how-to's or help from someone using this already, really appreciated.

Peter

1 Reply

I had this problem too… You have to have an account and a "license key". The website is kind of unclear on this and I don't remember what exact steps I took to accomplish this. I do remember that it was pretty frustrating.

I don't use the Debian package…rolled my own app. I have a cron job that downloads the MaxMind databases. It kinda looks like this:

#!/bin/bash
#
LICENSE=<redacted>  # <<= from maxmind.com

LOC="https://download.maxmind.com/app/geoip_download?license_key=${LICENSE}&edition_id=GeoLite2"

TMPBASE=/tmp/GeoLite2

CURL=/usr/bin/curl       # change me if you're on Darwin or FreeBSD
TAR=/bin/tar             # change me if you're on Darwin or FreeBSD
UNZIP=/usr/bin/unzip     # change me if you're on Darwin or FreeBSD

function csv
{
    local db
    local dst

    db="${LOC}-${1}-CSV&suffix=zip"
    dst=${TMPBASE}-${1}-CSV.zip

    $CURL $db -s -o $dst
    $UNZIP -o -qq $dst

}

function mmdb
{
    local db
    local dst

    db="${LOC}-${1}&suffix=tar.gz"
    dst=${TMPBASE}-${1}.tar.gz

    $CURL $db -s -o $dst
    $TAR xzf $dst

}

function get
{
    pushd 2>/dev/null

    cd /tmp
    for i in City Country ASN
    do 
        csv $i
        mmdb $i
    done

    popd 2>/dev/null
}

get

# fin
#

Here's the crontab entry:

# update the geoip databases (every Wednesday)
#
0   2   *   *   3       nice -n 19 /srv/geoip/bin/cron/geoipupdate

The name of my script is /srv/geoip/bin/cron/geoipupdate and it runs at 2am local time every Wednesday (I believe the free databases are updated on Tuesdays).

This is the bare bones… It retrieves all the compressed tars of the .mmdb & .csv files into /tmp/GeoLite2 for processing by later stages of the script (I build an SQLite database from the CSV files). There's enough here to facilitate adaptation for your own needs.

Enjoy!

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct