Geolocation - GeoIP2 Apache broken


#1

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


GeoIP2 HTTP Server Module: Matomo cannot find any GeoIP $_SERVER variables
(Daniel Städeli) #2

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?


(Thomas W) #3

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?


(Lukas Winkler) #4

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)


(Pas) #5

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


(Lukas Winkler) #6

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.


(Pas) #7

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.


(Stefan Giehl) #8

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…


(Pas) #9

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….


(Fabian Dellwing) #10

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.


(Pas) #11

Yes, of course, they are correctly set:

Any other ideas where to look?


(Pas) #12

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:


(Josh) #13

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.


(Pas) #14

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).