Last night when I was moderating some comments on TechPP, I was shocked to see an error page instead of the admin panel dashboard. The error read something like this –

PHP Fatal error: Out of memory (allocated 49545216) (tried to allocate 77824 bytes) in /home/xxxxx/public_html/xyz/admin.php(1758) on line 40

The first thing I could think of was to restart the Apache httpd service. This immediately solved the issue. but I knew this is not a permanent fix for the issue. When I researched further, I got to know that the error comes when certain PHP scripts require more memory than PHP was allowed by default.

So the solution is to increase the memory allocated for PHP. How to do that? There are 4 possible ways –

1. Try looking for the php.ini file. You might find some redundant php.ini files, so make sure you have got the one which is actually being read by PHP. o be sure, create a new php file in your root folder, say “check.php” and have phpInfo(); within the php open and close tags. Execute this file to get the information on where the php.ini is residing. Normally it will be in /usr/local/lib/php.ini

Open the php.ini file in a text editor like TextPad (not in Notepad) and change the values for memory_limit. By default you should see memory_limit = 8M. Try changing it to 12M. If it doesn’t work, increase it to 16M or even 24M and so on.

2. In case you can’t find the php.ini file or do not have access to it, then open up the file which was throwing the error (admin.php in my case) and add a line below just after ini_set(’memory_limit’, ‘12M’);

3. You can even consider adding a line in .htaccess file which will resolve the issue.
php_value memory_limit 32M

4. Or else, Try adding this line to your wp-config.php file:
Increasing memory allocated to PHP
define('WP_MEMORY_LIMIT', '32M');

If none of the above things solve your issue, then talk to you host. If you have a host like Knownhost who is fast and knows what needs to be done, you do not have to worry much.

Note: I am now worrying on which PHP script required an increase in memory allocation. The analysis won’t be so easy though.

Image Courtesy: Clarkandransom


Raju is the founder-editor of Technology Personalized. A proud geek and an Internet freak, who is also a social networking enthusiast. You can follow him on Facebook and on Twitter. Mail Raju PP. Follow rajupp


  • http://webguy303.com Web Guy 303

    Nice info – I’m currently trying to work around a memory allocation error and you have some ideas I haven’t found on other sites, I’ll be giving these ideas a try shortly

  • http://www.niharsworld.com/ Nihar

    Hey, i think i also seen this error. but, it was due to plugin not compatible with 2.8. but it is good that you learnt something corrected it and sharing here.

  • Vincent

    “So the solution is to increase the memory allocated for PHP”

    Isn’t it a better solution to try and find out what causes PHP to use so much memory? And fix that instead?

    • http://techpp.com Raju

      that’s not something easy. There is no easy way to find out which process/plugin is taking in extra memory. In case it goes beyond a point, you can start disabling plugins one-by-one to see if it improves memory consumption.

  • http://www.ashishkulkarni.com Ashish


    I agree with Vincent. Throwing more memory at something that has memory leaks can only make the problem go away for a while. It will still be there and may come back.

    Best thing to do is to try and get rid of the underlying issue.

  • kevin

    I am having the same error issue, I don’t have shell access to my site, but have had the provider up the php limit to 64M. I was getting errors with varying allocated memory sizes.

    I still am getting the errors, I put in a plug-in to monitor the memory the stats below are what it shows:
    * Usage Sample: 26.18MB (41%)
    * Peak Usage: 26.92MB (42%)
    * All-Time: 30.85MB on 3/25/10 @ 3:59 am (shutdown)
    * Load Averages: 0.54 0.55 0.54
    * WP Memory Limit: 64M
    * PHP Memory Limit: 64M

    most of the recent errors have an allocated memory of 20971520 which I believe is 20M, yet I cannot find where that setting is, and as shown below it occurs in different plug-ins.

    I am stumped.

    maybe I will disable various plug-ins until it stops. :(

    Fatal error: Out of memory (allocated 20971520) (tried to allocate 122880 bytes) in /home/weaver/public_html/wordblog/wp-includes/pluggable.php on line 342

    Fatal error: Out of memory (allocated 20971520) (tried to allocate 24577 bytes) in /home/weaver/public_html/wordblog/wp-settings.php on line 601

  • MaXfReZa

    I’ve tried 4th option: define(‘WP_MEMORY_LIMIT’, ’32M’);

    But I used ’64M’ instead of ’32M’ because my default settings was set to ’40M’. I’ve been trying to bring the error out by clicking to and from the home page but I don’t see the error anymore. Thank God for blessing Raju with a means and a will to help others.

    My site is moving faster, which nice side-effect :-)

  • Vasim Padhiyar

    nice article,
    i am trying to upload 4 MB image but it gives me fatal error : Out of Memory. although i have 40 MB set in phpini

    is there any more setting required.

  • Nicola

    Hi, I have tried doing the options you suggest except 2 – apologies but I was unsure what to put and wondered if you can help:

    The error I get is 2Fatal error: Out of memory (allocated 32243712) (tried to allocate 3098505 bytes) in /homepages/0/d132202164/htdocs/blog/wp-includes/class-http.php on line 1421″ so I’ve tried editing the class-http.php file but there are a few ini-sets and I was unsure where / how to add it in

  • mike

    Just had the same problem, instead of just applying this type of technique. Try actually figuring out what might be the problem before adding this update to the ini.php file.

    I’ve have 1and1 and solved my problem without having to touch the ini.php file.

    Go through your plugins, edit where need be..

  • http://kate-coleman.blogspot.com Kate

    I am having this same problem, but these solutions are a bit over my head. Anybody have the time/inclination to explain it to me a little bit more in-depth? Is this even something to do with MY PC or does it have to do with the site I’m trying to upload the image to?

  • Manoj

    Really nice article, it has really helped me to solve my blog’s problem.

  • Yamenator

    Does this solution apply to localhost?

    I am generating a random password using php srand( (double)microtime()*1000000 ) and I am getting the same memory error testing on

    Should I upload to remote and test to see if that resolves the memory error or will it not make a difference?

  • Sascha Mittler

    Hi, I had the same problem but no rights to edit “php.ini”. Here is what I did -> http://www.stadtklatsch.com/2012/06/04/piwik-fatal-error-out-of-memory-etc/ . This article is written in german, but maybe someone can use it anyway.

  • Anu

    thanks for the solution and it’s a very nice article.

  • SamGenius

    You F*cked up my server by adding this php_value memory_limit 32M i add it through ftp in .htaccess file and its showing 500 server internal error.

    • JimDoofus

      maybe remove then, “genius”?

    • WTF?

      LOL what a moron

  • http://www.webbusinesslife.com Inspiredly Written

    See http://stackoverflow.com/questions/12172515/set-memory-limit-in-htaccess

    If your server API is CGI Host Server Type, you cannot use php_value commands in .htaccess. Hence 500 internal error.

  • http://letthemenvy.com Tia | LetThemEnvy.com

    This doesn’t work for 1and1

  • Jena

    so your solution was a work around and not a solution itself! what if the PHP memory_limit keeps growing?