Installing geoip2 required library for Smart IP's data source MaxMind GeoIP2 binary database

The MaxMind GeoIP2 binary database is a custom binary format and there are two available APIs that read this binary database: MaxMind DB Reader PHP API which includes an optional C extension that you may install to improve binary database lookup performance and the default is GeoIP2 PHP API. We will discuss how to install these two APIs in your system.

The following procedures are tested on my Linode server running Centos 7 64-bit Linux distribution.

  1. Install composer:

    curl -sS | php
    mv composer.phar /usr/local/bin/composer

    Follow this instructions installing composer in Windows.

  2. We can install GeoIP2 PHP API library in two ways: one is directly install GeoIP2 PHP API library on your Drupal base:

    cd /var/www/
    composer require geoip2/geoip2:~2.0

    Note: change /var/www/ to your Drupal root path.

    ... and the other way is by installing Smart IP module using composer which will install the GeoIP2 PHP API library automatically.

    If you downloaded the Smart IP module directly from its project page and extracted it manually to your Drupal installation, you will want to use the first way.

  3. (Optional) Now lets install the other API, the MaxMind DB Reader PHP API. First, install the library. Go to your Drupal root path and execute:

    composer require maxmind-db/reader:~1.0

Installing MaxMind DB Reader's PHP C Extension

  1. Install the development tools:

    sudo yum install php-devel autoconf automake gcc libtool
  2. Download and compile the libmaxminddb:

    cd /opt
    git clone --recursive
    cd libmaxminddb/
    autoreconf --install

    You may encounter this (ignore it):

    autoreconf: automake failed with exit status: 1

    Continue with the rest of commands to compile libmaxminddb:

    make check
    sudo make install
    sudo ldconfig
  3. Next, compile the PHP C extension. In your Drupal root path, execute:

    cd vendor/maxmind-db/reader/ext
    make test
    sudo make install
  4. Add the compiled PHP extension in your php.ini or in /etc/php.d/maxminddb.ini:

    echo "" > /etc/php.d/maxminddb.ini
  5. Lets check if everything are installed properly:

    php -i | grep maxmind

    You may encounter this error message:

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/' - cannot open shared object file: No such file or directory in Unknown on line 0

    To solve this, execute:

    sudo sh -c "echo /usr/local/lib  >> /etc/"
    sudo ldconfig
  6. Restart your web server.

    Go to and scroll down, you should see something like this:

    maxminddb PHP extension loaded sucessfully

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.