Skip to main content

How to fix a PHP Fatal error: Allowed memory size of XXXXX bytes exhausted

If you're working with a PHP website, Magento in my case, and you get a page that is half blank when loading it's possible that you're experiencing a fatal PHP error.  This quick post will show you how to fix this in Magento

  1. Verify that you're getting a fatal PHP error related to memory size
  2. Update your .htaccess file
  3. Update your php.ini configuration

Step 1:  Verify the error

To verify that you are experiencing a fatal PHP error related to the memory size available you must first find your PHP error log file.  My host provides this through cPanel but if you're using your own Apache server it can usually be found in /var/logs/apache2/errors.log (see below).

Open using whatever editor you like (geany in my case), when opened, I was seeing this:

Apache2 error.log file showing a PHP Fatal error

My log was giving this error:

[23-Nov-2011 17:13:12] PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 169556 bytes) in /path/to/magento/app/code/core/Mage/Core/Block/Abstract.php on line 888

If you get something similar, the PHP script is trying to use more memory than is  allocated by the current PHP configuration.  There's two steps to fix this in Magento.

Step 2: Update the .htaccess file

Open the .htaccess file is located in your magento webroot in my case public_html.   Find the php_value memory_limit line and set it to a higher value.  I changed mine from 64M to 256M, ideally you want to keep this as low as possible. So anything like 96M, 128M, etc.. will work.

## adjust memory limit

#    php_value memory_limit 64M
    php_value memory_limit 256M
    php_value max_execution_time 18000

Also make sure your max_execution_time is large enough as working with large executions may cause an error if exceeded.  I left mine at 18000 (see below).

Set the php memory_limit in the Magento .htaccess file

Step 3: Update the php.ini file

Lastly we have to set the same memory limit in the PHP configuration (depending on your server setup).  If you're webroot has a php.ini.sample, file you can simply rename it to php.ini and then edit the memory_limit and max_execution_time as follows:

; This file is for CGI/FastCGI installations.
; Try copying it to php5.ini, if it doesn't work
; adjust memory limit
memory_limit = 256M
max_execution_time = 18000

When finished the php.ini file should look similar to the picture below, save it to your webroot.
Set the memory limit in the php.ini

Now save and reload the page that was failing to load before.  Good luck!


  1. Thanks for the post
    very useful for me.

  2. hi, May I know what kind of Hosting you are using?
    I have a problem with Site5's shared host (store with 14k products) and they suggest me to change to VPS.

    Although I did all the thing above (and tried many other different on magento forum), it didn't work out.

    So May I know your shared host so I can change to?
    Thank you.


  3. Nice Way. Thank you so much :)

  4. thanks for posting, very helpfull, but i still having this error when i uploading easted of the fact that i increase the max_post data size and the max size of the upload file en php.ini. something it works something i have the error, do you have an idea for me, thanks.

  5. A debt of gratitude is in order for the post
    extremely valuable for me.
    Article Submission sites| Latest Updates| MBA Talks


Post a Comment

Popular posts from this blog

Kivy vs React-Native for building cross platform mobile apps

I've built three apps now using Kivy and one with React-Native, just wanted to share my thoughts on both. Just a warning, I am strongly biased towards python and this is all based on opinion and experience and is thus worth what you pay for it. I don't claim to be an expert in either of these, just have worked with each for several months.  If something is incorrect I'd love to hear advice. Kivy Demo of one of the apps Pros: Nice to be able to run natively on the desktop WITHOUT a simulator Python is easy to work with Use (almost) any python library Very easy to create custom widgets Kivy properties and data binding just work. Way nicer than React's "state" / flux / redux whatever you want to call it (stupid?).  Native interfaces (pyjnius) and (pyobjc) Runs and feels pretty smooth Cons: Default widget toolkit looks like Android 4.4. Requiring you use your own widgets or a theming kit like KivyMD  if styling bothers you Creating dy

Control Systems in Python - Part 2 - Routh Hurwitz

In my last post Control Systems in Python Part 1 , i described how to setup and use Python for doing some basic plotting of transfer functions. One of the biggest benefits of using sympy vs numeric packages like matlab/numpy/scipy is the fact that you can use symbolic variables. This post includes a function for computing the Routh Hurwitz table (Note: It does not work for row's of zeros). Lets do my control systems design homework problem together :) (Warning: I have not verified if this answer is right so please correct me if it’s not!) The Problem The problem is DP 9.11 from Dorf & Bishop’s Modern Control Systems. ISBN 0136024580. Basically we have to design a controller to compensate for a system with a time delay. The controller is: And the system is: First we approximate the exponential term with a 2nd order polynomial using pade(0.4,2) such that: Thus the approximated system is: Using frequency response methods, design the controller so that th

Control Systems in Python - Part 1 - Bode and Step Response

I hate matlab with passion, yet sadly, nearly everyone uses it.  I'm a fan of Python and open source stuff so here's a simple article on how to do some common control systems stuff in Python. First we need to make sure the environment is setup. Install IPython (or you can use any other python shell, but a unicode supported shell is preferred) Install python-control (numpy, scipy) Install sympy These should do if your on Ubuntu/debian: sudo apt - get install python - sympy python-numpy python-scipy python-matplotlib ipython Then you need to install python control, see How to download and install python-control Intro to using Sympy Open ipython and run the following: import sympy from sympy import * sympy.init_printing() s = Symbol('s') Now we can do things like define transfer functions using the symbolic variable s. We can expand the bottom using the .simplify() method and we can do something more complex like... which is really nice because it