MaxMind GeoIP Symfony2 Bundle

Installs: 734 657

Dependents: 2

Suggesters: 0

Security: 0

Stars: 26

Watchers: 5

Forks: 32


v1.1.5 2018-02-07 23:32 UTC

This package is auto-updated.

Last update: 2020-01-24 10:20:27 UTC


Symfony bundle to easily use maxmind geoip bundle.

SensioLabsInsight Build


To install this library please follow the next steps:

First add the dependencie to your composer.json file:

"require": {
    "maxmind/geoip": "dev-master"

Then install the bundle with the command:

php composer update

Enable the bundle in your application kernel:

// app/AppKernel.php

public function registerBundles()
    $bundles = array(
        // ...
        new Maxmind\Bundle\GeoipBundle\MaxmindGeoipBundle(),

Now the library is installed.

To get the maxmind data source file (in '.dat' format), you can choose between one of the two following purposed methods:

You can go on the maxmind free download data page: And get the needed version. Then you have to unzip the downloaded file in the data directory located in 'vendor/maxmind/geoip/data'.

Or you can simply execute this command:

php app/console maxmind:geoip:update-data %url-data-source%

Replace %url-data-source% with the url of the needed data source. ex:

If you want to use your data file in another directory, you can configure it on app\config\config.yml

# app/config/config.yml
	data_file_path: "%kernel.root_dir%/../web/GeoIPCity.dat"

Now can use the Maxmind GeoIp Library everywhere in your Symfony2 application.


The following examples are available if you are in a controller

$geoip = $this->get('maxmind.geoip')->lookup(%IP_ADDR%);


Or in twig file

{{ ip|geoip.countryCode }}
{{ ip|geoip.countryCode3 }}
{{ ip|geoip.countryName }}
{{ ip|geoip.regionCode }}
{{ ip|geoip.region }}
{{ ip| }}
{{ ip|geoip.postalCode }}
{{ ip|geoip.latitude }}
{{ ip|geoip.longitude }}
{{ ip|geoip.areaCode }}
{{ ip|geoip.metroCode }}
{{ ip|geoip.continentCode }}

You can add a demo route in your 'routing_dev' to get an example on how this bundle work for example:

    resource: "@MaxmindGeoipBundle/Controller/DemoController.php"
    type:     annotation
    prefix:   /demo

Get a lookup at /demo/geoip

This library is an import of Maxmind GeoIp Free Library, you can find at