Blog Post

Increase PHP Memory Limit

Anyone working with WordPress (or any other PHP-based system) has seen one of PHP’s most common fatal errors: Allowed memory exhausted. Depending on your host and personal preference, several methods exist to increase the memory limit.

Older WordPress versions (before 2.9) could work with 16M of PHP memory. Even later, 3. x versions can work with so little memory if you don’t use any plugins. But, using plugins increases memory requirements, and using only 32M is usually insufficient. For the latest WordPress, with an average of 20 plugins, you will need 48M to 64M. Most hosting companies keep this value at 32M, so when you upgrade WordPress, upgrade the plugin, or add new plugins, you will run out of memory, and you will see the variation of this error (on-screen or in the log, depending on server settings):

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 345234 bytes) in /path/to/public_html/wp-content/plugins/plugin.php on line 56.

You can use different methods to increase memory. The examples below are for 64MB of memory. You can set it lower and experiment with higher values. Setting this to 128M or 256M is fine; PHP will use it as needed, but this value is the limit. Use only one of these methods; don’t use all of them at the same time!

Method 1: Change PHP.ini

On some shared hosting servers and on VPS or other dedicated hosting, you will have access to the php.ini file with all main PHP settings. This file should have a memory directive, so you need to find it and change it. If it is not there, you need to add it.

PHP.ini memory settings
PHP.ini memory settings

Here is the directive you need to find/add and set the different values for memory size:

memory_limit = 128M

Method 2: Use .htaccess

If you don’t have access to php.ini, the same can be done using the .htaccess file. This file is in your website’s root folder; if it’s not there, you can add it, but WordPress usually adds it. This file is only available on Apache servers. Again, search for this in that file; if it is not there, add it and set the memory value you need:

php_value memory_limit 128M

Method 3: Use WordPress wp-config.php

WordPress does this using the almighty wp-config.php file. If this definition is in the file, change it to the memory value you want; if it’s not there, add it before the “That’s all, stop editing!” comment in that file. Here is the code to find and change or add if it’s not there.

define( 'WP_MEMORY_LIMIT', '128M' );

Method 4:  Hosting Variable

Some hosting companies can have the option to change the memory limit directly without editing any files. It is usually found inside the hosting panel for PHP settings. Check out your hosting panel documentation for more information.

Method 5:  Contact your hosting company

If you don’t want to do it yourself, contact your hosting company’s support. Some hosting companies can limit this value, so whatever you try to change will fail, and only hosting support can change it for you (if they want to). If you can’t change the memory limit, it is time to find better hosting that will allow you to do so.

If an increased memory limit doesn’t solve your problem, you may have a memory leak that needs to be fixed in the code that caused it. Check out this tutorial for more information.

Please wait...

About the author

Milan Petrovic
Milan Petrovic

CEO and Lead developer of Dev4Press Web Development company, working with WordPress since 2008, first as a freelancer, later founding own development company. Author of more than 250 plugins and more than 20 themes.

Subscribe to Dev4Press Newsletter

Get the latest announcements, release digests, promotions and exclusive discounts, and general Dev4Press-related news straight into your mailbox.


This form collects your email (optionally your name) for the purpose of sending you newsletters. Check out our Privacy Policy for more information on how we store and manage your data. We will not send you any spam. Newsletters are sent 2 to 4 times every month.

Latest From The Blog

plugins release sweeppress pro 5 2

SweepPress Pro 5.2

Version 5.2 is a minor scope update that brings a new shared library, expanded lists of values for CRON, options, metadata detections, improvements to the CRON panel filtering, and a few fixes.
plugins relase gd topic prefix pro 4.0

GD Topic Prefix Pro 4.0 for bbPress

A brand new major update for GD Topic Prefix Pro for bbPress is released, and version 4.0 is a smaller scope update that completes all the previous development plans, updates the shared library, and more.
plugins relase gd power search pro 2 6 lite 2 0

GD Power Search Lite 2.0 & Pro 2.6 for bbPress

The fully updated Lite version overhaul is finally ready and available as version 2.0, based on fully updated Pro version 2.6, also available now. This includes various updates and improvements and the latest version of the new shared library.

Leave a Comment

SiteGround - Managed WordPress Hosting
Grammarly - Number 1 Writing App
0
0
0
0
0
0