Piwik installer has PHP Fatal error: Allowed memory size exhausted (tried to allocate 20480 bytes) in core/FrontController.php

Published Wed Aug 30 2017

For three nights I struggled with trying to figure out why I could not get Piwik’s web analytics software to load it’s installation page successfully. I was attempting to migrate it from a FreeBSD 10 server to a FreeBSD 11 jail and nothing, nothing I did was working. I kept on getting the following two errors in my php logs:

PHP Fatal error:  Allowed memory size of xxxx bytes exhausted (tried to allocate 20480 bytes) in /usr/local/www/piwik/core/FrontController.php on line 416
PHP Fatal error:  Allowed memory size of xxxx bytes exhausted (tried to allocate 20480 bytes) in /usr/local/www/piwik/core/FrontController.php on line 227

This message seemed to be telling me that my php process was running out of memory. The reason this was so puzzling is that I took my PHP configuration files from another jail running different PHP software, that had worked! I could not fathom why the same files would not successfully serve (with minor modifications) piwik.

As it turns out, the php configuration files were not the problem. It was missing php modules that caused the issue. How did I figure this out? Well, in desperation I decided to just go back in time (one piwik version at a time) to see if any would work. I eventually saw a different error with version 3.0.0. Even better, I knew what this one meant.

The error was:

Error in Piwik: Call to undefined function Piwikctype_alnum()

This indicated that I was missing the php ctype module, so I installed it with pkg install php71-ctype. Then I received another error:

Error in Piwik: Call to undefined function hash()

This indicated that I was missing the hash module. A quick pkg install php71-hash later and I finally had what I needed: the Piwik installer. Having found success, I then went back to the latest Piwik version. And lo, It worked!

Here is the final list of php module packages I installed:

php71
php71-pdo
php71-pdo_mysql
php71-curl
php71-filter
php71-hash
php71-ctype
php71-session
php71-json

Hope this saves you 3 days.