How to fix PHP memory Fatal errors allowed memory size in Magento

0

Due to the robust design, unfortunately, Magento may confront with memory intensive issue. The error may be like this PHP Fatal error: Allowed memory size of 45108864 bytes exhausted (tried to allocate 157556 bytes) in path/to/file.php

Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 130968 bytes) in /var/www/magento/app/code/core/Mage/Core/Model/Resource.php on line 199

Users, however, are able to adjust the memory limits in order to solve the memory errors. This tutorial will show you how to fix those errors by adding codes into 2 files separately.

Step 1. Login to the Account Management Panel and under your account name, click the cPanel button to be redirected to the cPanel. Then, open File Manager.

Step 2. Click on Settings in the top right corner of the working space and navigate to root folders of your Magento Installation.

Step 3. Go to the index.php file and have a right click. Select Code Edit then click Ok.

Quick note: If you have access to FTP or SFTP, you can navigate to the same file location to make changes to files using Filezilla or CuteFTP, Winscp.

Step 4. Add this line of the code right after <?php tag in index.php:

You can set the value more than 768M to ensure that there’s enough PHP memory for handling Magento tasks

Step 5. Click the Save Changes button in the upper right corner of working space:

php memory limit magento

Step 6. Return to the File Manager to go to app/Mage.php file. Right click and select Code Edit as previously.

Step 7. Add the following code to the first line:

Step 8. Click the Save Changes button in the upper right corner of working space:

ini_set("memory_limit","768M");

Step 9. Check if the issue is fixed, if not, you should also change php memory limit in two files: php.ini and .htaccess file

For php.ini, go to /etc/php.ini, edit file and add the following lines:

For .htaccess, go to your Magento installation folder, edit and add the following lines:

After everthing is done, restart your apache to apply changes using:

Step 10. Reload your website to ensure there is no further memory issues exist.

That comes to the end of the tutorial. If you have any further questions on this topic, please comment below to let us know.

How to fix PHP memory Fatal errors allowed memory size in Magento
5 (100%) 2 votes

Share.

About Author

Daniel is a Magento developer with 5 years of experience with customizing Magento extensions, Magento templates. He's main author at Magento explorer

Leave A Reply