Geolocation - GeoIP2 Apache broken

Hello,
I have installed MaxMind DB Apache Module.
Now I am in setting of Matomo and in section Geolocation is:
GeoIP2 (Apache)
Broken

Error: The MM_COUNTRY_CODE $_SERVER variable is not set. Your server may not be configured correctly.

Matomo cannot find any GeoIP $_SERVER variables.

in my /etc/apache2/apache2.conf

###GeoIP - MaxMind
MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /usr/local/share/GeoIP/GeoLite2-Country.mmdb
MaxMindDBFile CITY_DB /usr/local/share/GeoIP/GeoLite2-City.mmdb

MaxMindDBEnv MM_COUNTRY_CODE CITY_DB/country/iso_code
MaxMindDBEnv MM_COUNTRY_NAME CITY_DB/country/names/en
MaxMindDBEnv MM_CITY_NAME CITY_DB/city/names/en
MaxMindDBEnv MM_LONGITUDE CITY_DB/location/longitude
MaxMindDBEnv MM_LATITUDE CITY_DB/location/latitude

Thank You for any help

1 Like

Hi, I have exactly the same problem and Iā€™m stuck for 2 days trying to get rid of this error. What did you do to fix this?

Hello, I have the same error message ā€œError: The MM_COUNTRY_CODE $ _SERVER variable is not set. Your server may not be configured correctly.ā€
Have everything as described by maxmind, created.
The Apache Module maxminddb is enabled.
MaxMindDBEnable, MaxMindDBFile and MaxMindDBEnv set on apache2.conf

Matomo-Version: 3.7.0

I do not know
How can I fix it?

Hi,

I know little about Apache, but if $ _SERVER["MM_COUNTRY_CODE"] is undefined then either the Apache extension is not set up correctly or the variable is called something different than MM_COUNTRY_CODE. (You can set this up in the Matomo General Settings)

Hi Lukas,
Iā€™m turning around this error since many days. Looking for a solution without success. Seems to me a configuration error, but cannot find where the error is. In the ā€˜system checkā€™ I get:
ā€œGeolocation works, but you are not using one of the recommended providers. If you have to import log files or do something else that requires setting IP addresses, use the PHP GeoIP 2 implementation and install [maxminddb extension.ā€

If I look on System>Geolocation:
I see ā€œGeoIp2 (Apache) brokenā€ and the message:
" Error: The MM_COUNTRY_CODE $_SERVER variable is not set. Your server may not be configured correctly."
And
" Matomo cannot find any GeoIP $_SERVER variables."

And if I look at ā€œGeneral Settingsā€ the Variables are correctly given.
In /etc/apache2/mods-available/maxminddb.conf the module is on and the file path and dbenv are set.

In other words I dont know where to look to activate the GeoIp2 (geolocation) within Matomo.
Thanks in advance for your help.
Matomo ver. is 3.8.0

Hi,

Please make sure that Apache is really putting the data into these variables. You could try creating a simple PHP script that outputs verything in $_SERVER.

<?php
var_dump($_SERVER);

This should show you a long list of variables and MM_COUNTRY_CODE should be one of them. If it isnā€™t, then Apache isnā€™t set up correctly.

Hi, I made few tests by adding the: var_dump($_SERVER); command and I get correctly the results accesing the page. See attached:

Why still I have in the Matomo Administration the System check warning? By my point of view the GeoLite is correctly configured. I suspect instead something wrong elsewhere.

1 Like

Are you sure those variables are set for the vhost Matomo is running on? If $_SERVER['MM_COUNTRY_CODE'] is set, it shouldnā€™t be reported as broken.
Just did some local tests and it worked fineā€¦

Iā€™m not an Apache guru but I think the variables are correctly set.
See attached the three screen grab which include:
VirtualHost conf
MaxMindDB conf
Matomo System settings error


Dont know where to look elseā€¦.

Please take a look at System -> General settings. You can there setup the variables that Matomo will use. Please check if you have the correct variable names there.

Yes, of course, they are correctly set:

Any other ideas where to look?

Forgot to tell that Iā€™m running on a Debian 9 Stretch, maybe is an useful information.
Any ideas? Iā€™m stll turning around :frowning:

Donā€™t know if you are still having this issue but the solution for me was to connect over public internet. I was initially testing on my vpn connection and since my ip was local, it was reporting the Plugin was broken. Like you I was able to create a test.php and it returned the correct variables. Finally I disconnected my vpn and accessed matomo over public ip, logged in as admin and the plugin was green and working. Not sure if thats just a bug in the admin ui or what. Hope that helps.

It is exactly as you wrote. Thank you!
Since Iā€™m accessing from the local LAN (private IP address) the Apache GeoIP is broken. Once accessed from the public IP I finnally enabled successfully the GeoIP plugin wich started to show me the correct accessing location.
It is obvious that something is wrong also with the latest version of Matomo and ask the developers to look at it.
Seems to be simple to reproduce: just access from the local private IP address Matomo as administrator and try to set the GeoIP (it will be shown as broken).

1 Like

GeoIP is a database which links IP addresses to locations.
I donā€™t expect it to have data for private IP addresses.

For instance, when you are in your Matomo settings:
Matomo >> >> System >> Geolocation, if you are in a public IP the location will show here:

But if you are in a private IP, the table cannot look up your location because there is no corresponding entry in the database.

You can overcome this be entering your own list of IP : location data in the plugin Campus IP.

This is a module for building your own list of IP : location data. You must start by already having this data in a list. You can then import it to the Campus IP module. (The module by default has no locations or IP addresses in it.) This is a third party plugin. Disclaimer: the code is not by us. It is opensource and inspectable and as of now we have not had complaints about it from any users.