Are you fed up with the Magento PHP memory limit errors?
Insufficient PHP memory limit often results in the error Allowed memory size of XXXX bytes exhausted.
The fix involves increasing the memory allocated to the right PHP version in the server.
At Bobcares, we often get requests from our customers to increase the PHP memory limit in Magento as part of our Server management services.
Today, let’s get into the details on how our Support Engineers increase the PHP memory limit and fix related errors.
Magento: Allowed memory size exhausted! Why?
The Magento PHP memory limit sometimes throws an error Allowed memory size exhausted either in the log file or while accessing the website.
By default, the memory_limit value in the PHP configuration determines the amount of memory allotted for the PHP script.
Often customers set insufficient values in the PHP configuration. Thus, during a fresh installation, even the readiness check display the error message:
Similarly, when the PHP scripts are resource-intensive, we can also find the error in the log file of the website as follows:
The error message indicates that by increasing the global memory_limit in the servers php.ini configuration file we can fix this problem.
Methods to fix Magento PHP memory limit error
The releases of Magento1 and Magento2 differ slightly. Magento 2 is the new version and it supports the latest PHP. It also improves the overall speed of the site. It can take more orders per hour and page loads faster than Magento 1.
At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers face problems with the exceeded memory limit in Magento.
Now, let’s see, how our Support Engineers fix this error by increasing the PHP memory limit.
Initially, before editing a configuration file, we always take a backup of the file. If anything goes wrong, this helps to easily restore it.
1. Editing php.ini file
The Magento documentation recommends at least 64MB as a default memory limit, then we can increase it according to the requirement.
The Magento 2 requires the memory_limit to be set to 756M or more.
Recently one of the customers was facing the same problem while upgrade from Magento CE 2.1.5 to 2.1.9 using Magento Updater.
After completing the readiness check the customer was continuously receiving the following error:
"Your current PHP memory limit is 2048M. Magento 2 requires it to be set to 756M or more. As a user with root privileges, edit your php.ini file to increase memory_limit. (The command php --ini tells you where it has been located.) After that, restart your web server and try again."
We assisted the customer by editing the servers php.ini configuration file by making the memory_limit to 756M. The easiest and common way to change memory_limit is via editing php.ini.
1. We searched the memory_limit option in the php.ini file and edited it to 756M.
memory_limit = 756M
2. After that, we saved the file.
3. Finally, we restarted the Apache using the following command:
This resolved the problem with the memory limit, and we helped the customer to upgrade from Magento CE 2.1.5 to 2.1.9.
Altering .htaccess file
In addition to this, when PHP runs as a DSO module, increasing memory_limit involves editing the .htaccess file.
Magento has a default .htaccess file in the root directory that includes the following configuration directive.
php_value memory_limit 64M php_value max_execution_time 18000
We then simply edited this value from 64MB to 96M or 128MB depending on the requirement. In all instances, our Dedicated Engineers double-check the phpinfo page and ensure that the new values show up.
[Need assistance in changing the PHP memory limit? We’ll help you.]
In short, the fix for the Magento PHP memory limit exceeded error involves increasing it by altering the value in php.ini, .htaccess, etc. Today, we saw how our Support Engineers changed the PHP memory limit in Magento.