matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.89k stars 2.65k forks source link

Cannot redeclare geoip_load_shared_mem() when running together with wordfence #11817

Closed Findus23 closed 3 years ago

Findus23 commented 7 years ago

From https://forum.piwik.org/t/geoip-conflict-w-wordfence/24651

If piwik is using the same geoip database as the wordpress plugin "wordfence" (via the GeoIP (Php) location provider) the following error occurs:

Fatal error: Cannot redeclare geoip_load_shared_mem() (previously declared in 
/home/USERNAME/public_html/wp-content/plugins/wordfence/waf/wfWAFGeoIP.php:240) in 
/home/USERNAME/public_html/analytics/libs/MaxMindGeoIP/geoip.inc on line 1444

I am not sure why two seperate php scripts are able to interfere, but it seems like this has happened to other projects.

A simple fix seems to be similar to this one: https://github.com/solarissmoke/Simple-Stats/commit/e25c459bb3600939c8fdd018e7094452c52f6334

mattab commented 7 years ago

Thanks for the report @Findus23 - the issue is that our geoip file cannot be included twice, which Wordfence has bundled the copy as well causing the error in our code. To solve this i think we need to wrap the file in a !class_exists looking whether GeoIp is already defined and possibly also wrap the functions below in function_exists.

RobsImpSS commented 7 years ago

Hopefully a fix will be included in the next update but is there a temporary fix for this issue as I have not had any statistics for well over a month now?

Thanks...

mattab commented 7 years ago

@RobsImpSS if you are using WP-Piwik with the "PHP" connection mode, try replace it with the "HTTP" option instead? this should fix the issue

RobsImpSS commented 7 years ago

I'm not using the WP-Piwik, just the regular version with the code inserted into the footer of WP. The reason why I do this is because I have a folder of website templates that I track and these are not created through WP.

As stated above, I get the fatal error in the Administration when I click the link to do a system check or click the Geolocation link. Piwik has always worked fine but I guess recent updates by Wordfence is conflicting with Piwik.

mattab commented 7 years ago

I don't quite understand how it is possible that wordfence influences Piwik in that way. When you load Piwik Administration screen, Wordfence/other tools shouldn't be able to affect the Piwik page rendering. Do you have some insights on why this is the case?

RobsImpSS commented 7 years ago

I am just a regular user of Piwik and it has always worked fine until about approx. 1.5 months ago. Then all of a sudden Piwik stopped recording visits and when I clicked on the System Check link in the Administration area, I got the error. I got the same error when I clicked on the Geolocation link as well.

Fatal error: Cannot redeclare geoip_load_shared_mem() (previously declared in /home/USERNAME/public_html/wp-content/plugins/wordfence/waf/wfWAFGeoIP.php:240) in /home/USERNAME/public_html/analytics/libs/MaxMindGeoIP/geoip.inc on line 1444

I then deleted my database and installed a fresh copy of Piwik, but the results were the same. I then disabled Wordfence and Piwik started recording visits again. So it was obvious that there was a conflict with Wordfence and that is when I opened a help request on the Piwik forum.

Findus23 commented 7 years ago

Maybe I know the cause and a possible solution:

Yesterday someone in the forum had a pretty similar issue: https://forum.piwik.org/t/piwik-konflikt-mit-wordfence-via-wordpress/24888/

His host recommended him to add php_value auto_prepend_file none into piwiks .htaccess, which solves the issue for him.

It seems like wordfence uses this php setting (with the help of an .user.ini php config or (if unsupported) with a .htaccess config entry) to insert a php file at the beginning of every file that gets executed (so also the piwik files), which causes this error.

RobsImpSS commented 7 years ago

I added it to the .htaccess file located in the config folder. Is that the right location? I copied and pasted it just as you typed it and it didn't fix it. Was copying and pasting okay or was I supposed to add any other characters?

Findus23 commented 7 years ago

I think the problem it that the line needs to be added to the .htaccess in the piwik root directory, as all piwik files shouldn't be prepended with wordfence code.

RobsImpSS commented 7 years ago

The Piwik root directory does not have a .htaccess file. I added a new .htaccess file to the Piwik root with the code you supplied and it caused a 404 error.

RobsImpSS commented 7 years ago

mattab,

Have you come up with anything yet?

Findus23 commented 7 years ago

The Piwik root directory does not have a .htaccess file. I added a new .htaccess file to the Piwik root with the code you supplied and it caused a 404 error.

Hi, changing an php setting inside an .htaccess shouldn't cause an 404. Can you check the php error log or the apache error log to see why this happens?

RobsImpSS commented 7 years ago

Here is the error I got (website url redacted):

[Fri Jul 14 11:12:58.251686 2017] [core:alert] [pid 246202:tid 140061798520576] [client 00.00.00.00:64124] /home/username/public_html/analytics/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration, referer: http://www.website.com/analytics/?module=CoreAdminHome&action=home&idSite=1&period=range&date=last30

sgiehl commented 3 years ago

This shouldn't be an issue anymore as we meanwhile switched to GeoIP2.