How to fix ‘Fatal error: Allowed memory size of X bytes exhausted (tried to allocate X bytes)’
The error, Allowed memory size exhausted, appears when PHP does not have enough memory to process a request from Matomo. This can occur when loading large reports or when a date range triggers temporary archiving. When you specify a date range, Matomo must generate the aggregated data on request, which requires more memory.
If PHP cannot allocate the required memory, the request fails. Clearing the Matomo cache does not resolve this problem because the issue is the PHP memory limit itself.
Check if the error is from PHP-FPM or PHP-CLI
Before fixing the issue, first identify which PHP environment ran out of memory:
PHP-FPM (for web and API requests)
- the error appears in the Matomo interface (for example, Behaviour > Pages).
- the error occurs during an API request (for example, exporting large reports).
- the error message includes
cli=0
PHP-CLI (for console commands)
- the error occurs while running
console core:archive - the error appears during any console command.
- the error occurs in a cron job running the archiver.
After identifying the source, you will need to increase the memory limit in the correct PHP configuration file. The sections below explain how to fix each case.
Fix the PHP-FPM memory limit
To fix a PHP-FPM memory error, confirm which configuration file PHP-FPM is using.
- If your Matomo server has a
phpinfo()page available, load it in your browser. For example,https://your-domain/phpinfo.php. - In the displayed PHP specifications, look for the Loaded Configuration File entry that shows the PHP-FPM configuration file path.
- Using the configuration file path, locate and open the
php.inifile. - Increase the value of the setting
memory_limitby doubling the value. - Restart PHP-FPM using
sudo systemctl restart php{version}-fpmand replace{version}with the PHP version installed on your server. - Reload the Matomo report and confirm the error is resolved.
Fix the PHP-CLI memory limit
This applies only when the error occurs during command-line execution (for example, archiving). You can optionally test with an ad-hoc memory limit or permanently increase the CLI limit.
- To test a memory limit, run the archiver with a higher memory limit:
php -d memory_limit=8G console core:archive - To permanently increase the CLI limit, find the CLI configuration file (this is usually different than the file which configures your server PHP):
php -i | grep "Configuration File" - Locate and open the php-CLI file.
- Increase the value of the setting
memory_limit. At a minimum, it should be 2GB. A common fix is to double the current value, for example, many installations use 4-8 GB depending on traffic volume. - Confirm the new value is active:
php -i | grep memory_limit - Re-run the command or reload the Matomo report and confirm the error is resolved.
Next steps
If the above steps do not resolve the issue, check for factors that consume memory during report generation such as using large date ranges, custom reports, or many active segments. Increase the memory limit further or reduce the size of the request (for example, use a shorter date range or simplify the report).