gpslab / geoip2

A Symfony Bundle for the Maxmind GeoIP2 API
https://www.maxmind.com/
MIT License
54 stars 12 forks source link

Issue with Symfony 4.4 integration - The file var/cache/dev/GeoLite2-City.mmdb does not exist or is not readable #59

Open MilesYM opened 4 years ago

MilesYM commented 4 years ago

Hi there,

I've followed the steps to integrate the librairy in my project. I've created a Service to use it in my code like so:

// src/Service/GeoipLib.php

namespace App\Services;

use GeoIp2\Database\Reader;

class GeoIPLib
{
    private $reader;

    public function __construct(Reader $reader)
    {
        $this->reader = $reader;
    }

    public function getCity($ip)
    {
        // get a GeoIP2 City model
        $record = $this->reader->city($ip);
        return $record->mostSpecificSubdivision->name;
    }

    public function getCountry($ip)
    {
        // get a GeoIP2 City model
        $record = $this->reader->city($ip);
        return $record->country->isoCode;
    }

    public function getPostalCode($ip)
    {
        // get a GeoIP2 City model
        $record = $this->reader->city($ip);
        return $record->postal->code;
    }
}

and my config file is as follow:

# Read the README file for more detailed configuration information
# https://github.com/gpslab/geoip2
gpslab_geoip:
    # You should specify your personal licence key
    license: 'XXXXX'

    # Edition ID of database you need
    edition: 'GeoLite2-City'

    url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=XXXXX&suffix=tar.gz'

If I follow the url, it does download the file so the key seems good to me.

However, when I'm trying to use the librairy, I'm getting the following error message:

The file var/cache/dev/GeoLite2-City.mmdb does not exist or is not readable

Indeed, it does not exist in the cache folder.

Please help. Thank you.

peter-gribanov commented 4 years ago

Good day

You need to download the database before starting work using the command:

php bin/console geoip2:update
MilesYM commented 4 years ago

That was it. Thank you my friend!

coredirection commented 2 years ago

i am getting this issue There are no commands defined in the "geoip2" namespace. after running above command