WordPress: Increase PHP Memory Limit

By default, WordPress consumes very little memory and should run fine on any type of hosting with ease.

At some stage or another, you may need to increase the memory made available to WordPress due to large applications or plugins running big processes.

Increasing WordPress memory limit can speed up plugins

 

Watch the Video

 

What determines the available memory?

The available memory which WordPress can use is determined on several levels really.

 

Physical Memory, OS & Webserver

The core factor that determines memory is literally the physical memory/RAM installed on the computer/server.

Then the operating system and webserver will allocate certain memory usage based on it’s configuration.

 

Server Side Language/Module

Ultimately, your server side language will determine, set and make available that memory that may be used.

In the case of WordPress, the server side language is PHP so the memory_limit of PHP will be configured globally on the server, for the domain specifically, WordPress could be setting a memory limit or a specific script could be applying a memory limit.

ram

It is quick and easy to increase memory limit

With PHP error_reporting turned on or WP_DEBUG set to true, your website running out of memory will no longer display a blank page or a 500 Internal Server Error but will then rather show a PHP memory limit fatal error such as this:

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in /home/xxx/public_html/wp-includes/plugin.php on line xxx

 

How to Increase PHP Memory Limit

There are several ways that PHP memory limit can be increased in WordPress.

Some may work and others may not so try these different ways (only one should be enough). The first option is usually the one that works:

 

1. Setting Memory Limit in wp-config.php

The quickest and easiest way is to open your WordPress installation’s wp-config.php file and set the WP_MEMORY_LIMIT constant with a value. The constant is not set by WordPress by default so you’ll need to add it at the top of your wp-config.php file like this:

<?php
define('WP_MEMORY_LIMIT', "256M");
?>

(https://gist.github.com/tribulant/30a85f1aa9c676e3403c)

Change the value 256M to the megabytes of memory you want to allocate. We suggest trying with 512MB.

 

2. Memory Limit PHP Directive in .htaccess file

Check if there is a .htaccess file in the root of your WordPress installation. It may be a hidden file. If it is not there, you can create it. Then in your .htaccess file, you can put the PHP directive at the top:

php_value memory_limit 256M

(https://gist.github.com/tribulant/c0b3655d543f98d8dcae)

We suggest trying with 512MB. If the above change gives a 500 Internal Server Error on your website you know that the configuration of PHP doesn’t allow directives to be changed this way. Remove the line and re-save the .htaccess to remove the 500 error and restore the website.

 

3. Changing Memory Limit in php.ini

You can either change the main php.ini file on your webserver’s PHP installation or you can try creating a new php.ini file inside the root of your website to see if it is effective. Then set the memory_limit in the php.ini file like this:

memory_limit = 256M

(https://gist.github.com/tribulant/b21b4df7e33060168574)

We suggest trying with 512MB. This shouldn’t cause any problems or errors but it may not be effective depending on your hosting.

 

4. Set PHP Memory Limit During Runtime

You can try setting the PHP memory_limit directive during runtime in wp-config.php or in the script that you’re trying to run. Do that using ini_set() like this:

<?php
ini_set('memory_limit', "256M");
?>

(https://gist.github.com/tribulant/d9b5c2f0c6853202fec3)

We suggest trying with 512MB.

 

5. Ask Your Hosting Provider

If none of the above methods allow you to increase your WordPress memory limit in PHP, you’ll need to ask the hosting provider.

Many hosting providers do not allow these values to be overridden manually by its hosting users for valid reasons while others do provide that flexibility.

Simply contact them via ticket/live chat and ask them to increase your PHP memory_limit for you. If they cannot, it may be necessary to upgrade to a higher hosting plan or even go as far as switching your hosting to a much more powerful WordPress hosting like ours which does allow it. We offer free SSL, free daily on-site and off-site backups, and free migration for normal-sized websites.

WordPress Plugins

Start selling products, sending newsletters, publishing ads, and more through your own WordPress website using our premium WordPress plugins.

Browse
Comments
  1. kwabs on January 4, 2018

    Hi,
    is there anything i must watch out when setting the Memory Limit via wp-config?
    I want to make the changes on a live Site and i dont want to crash it while increasing the Memory Limit.
    Any help would be appreciated. Thank you

    Reply
  2. HentaiWeeb on May 13, 2016

    Hi,

    At option 3, you mention editing the “php.ini” file. I’ve seen other people mention the same thing – however, I have no understanding of how to go about editing that particular file. Do you have a guide anywhere on how I could go about doing that? I’ve tried looking around and can’t make any sense of it.

    Yes, I’m pretty stupid.

    Any help would be appreciated, thank you!

    Reply
    • Antonie Potgieter on May 13, 2016

      @HentaiWeeb

      First thing, you’ll need to locate the php.ini file on your server.

      To do this, you can ask your hosting provider or you can create your phpinfo(); file as explained and that shows you where your php.ini configuration file is located.

      From there, you can go and edit the php.ini file in your terminal/command line. The php.ini configuration file will not be accessible via an account FTP and you’ll most likely need to login as root or a user with the correct privileges.

      The other alternative is to create a php.ini file and place it in the root of your website to see if it is effective.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Want More Content Like This?

Want More Content Like This?

Join our newsletter to get more content like this via email!

You'll receive a free, monthly email with a summary of very useful articles. No spam, just great content!

You have Successfully Subscribed!

Pin It on Pinterest