Wednesday, September 09, 2009

Increase the PHP memory limit with MAMP PRO

Most PHP applications can easily handle the default PHP memory limit of 8 MB. But more complex web applications, like content management- or blog-systems, do need an increased memory-limit. With MMAP PRO you can easily increase the PHP memory limit. Therefore you simply have to change some data within the php.ini file.

Here is how it works:
  1. Start MAMP PRO
  2. Stop the server if it's running
  3. Choose Menu -> File -> Edit Template -> PHP4 php.ini (If you want to change the memory limit for PHP5, then choose PHP5 php.ini)


  4. The PHP ini file will be opened.
  5. If a dialogue box pops up, read it and confirm with OK
  6. Search (Command-F) for "memory_limit" (without quotes)
  7. You should get the following line:
    memory_limit = 8M ; Maximum amount of memory a script may consume (8M)
  8. Now you can change the default value of 8M. For instance. into 32M or even more (like 128M)
  9. Save (Command-S) your changes.
  10. Close (Command-W) the file.
  11. Start the Server.
Now all PHP scripts can make use of the increased memory.

Please be aware of the fact that some ISP's are limiting the PHP Memory by default. This means, even if everything works fine on your local system, it probably will not work on the live system of your ISP.

Share/Save/Bookmark

23 comments:

  1. Thanks - that's a great tip and a big help. Explains why I've been getting a blank page in my php application.

    ReplyDelete
  2. This caught me out to when I was trying to import a Wordpress DB backup in phpMyAdmin (would only import 6 out of 19 tables) then crap out. Increasing the memory limit made all the difference.

    ReplyDelete
  3. Is there any chance that a site (taken from live and made local to work on fixing it up) might be too large for MAMP to handle? I have changed the memory limit as you show here to 128, but still get the white screen of death each time I save anything (literally, any changes I make to any component of the site) on my drupal site.

    Any thoughts? I'm at a complete loss and my sitework has been held up considerably....

    ReplyDelete
  4. @blank: Please check you php error log to see what's happen.

    ReplyDelete
  5. It gave only: PHP Fatal error: Call to undefined function _forum_get_vid() in /Applications/MAMP/htdocs/.../includes/common.inc(1685) : eval()'d code on line 2

    However, the same common.inc worked perfectly on the live site, and I haven't been successful with tracking down what might have been causing that particular error.

    Good news: it appears that there were exceedingly large tables in my database related to searching (we think perhaps form a Google search function we have on the site) that appear to be the culprit. We've dumped those tables and so far the local site is up and running as it should. Fingers still crossed!

    Any further suggestions you have would be wonderful though!

    ReplyDelete
  6. I followed the instructions above to no avail, at first.

    Then I took a look around for .htaccess files in my mamp htdocs directories, and sure enough, discovered that, for some reason, there was a memory limit directive imposed locally.

    So, if anyone followed the above directions and it didn't help, look for htaccess overrides!

    ReplyDelete
  7. I just installed a new version of MAMP Pro, and after going to File > Edit Template, it only shows PHP 1, PHP 2, and PHP 3, and they are all greyed out. How do I get it to show PHP 5 and make php.ini editable?

    ReplyDelete
  8. This article saved my ass! Thanks!

    ReplyDelete
  9. Thanks So much... been trying to solve this problem for ages, as it only happened with some sites.

    Great Work

    ReplyDelete
  10. Thank you so much, this has been a great help!

    Jen

    ReplyDelete
  11. Thanks, i was stuck after using Backup Buddy for transferring a live site to Mamp, and this worked :)

    ReplyDelete
  12. Very good article!! Thankyou very much!

    ReplyDelete
  13. Is there a way to do this in MAMP (not pro) ? I've changed the php.ini but no update in phpinfo().

    ReplyDelete
    Replies
    1. Hi Berkan, in phpInfo you can see the Loaded Configuration File: /Applications/MAMP/bin/php/php5.4.4/conf/php.ini
      Changing that file will probably work :)

      Delete
    2. Did not work, I tried it. The screen is still white. But thank you for the file directory.

      Delete
    3. Nope, didn't work. Thanks anyway.

      Delete
  14. This worked for me. Cheers :D

    ReplyDelete
  15. there is more than 1 way to increase the limit: http://newexception.com/php-increase-memory-limit

    ReplyDelete