Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Sep 3, 2020 · 3 comments
Assignees
Labels

Comments

@MilesYM
Copy link

MilesYM commented Sep 3, 2020

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
Copy link
Member

Good day

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

php bin/console geoip2:update

@peter-gribanov peter-gribanov self-assigned this Sep 3, 2020
@MilesYM
Copy link
Author

MilesYM commented Sep 3, 2020

That was it. Thank you my friend!

@coredirection
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants