php image

Quick and Easy way to increase your PHP Memory limit for WordPress

As your blog gets bigger you may have more plugins and scripts running some of these scripts can be demanding when it comes to memory. The default memory limit in PHP is 128MB this means that each script can use up to 128MB of ram per script not in total, in other words, it’s not a pool its per script

However, some plugins and scripts may not be the most memory efficient and may hit a wall with this memory size in this case a small change to either the wp-config.php file or .htaccess file will help with this check this out

First to make this change either use your favorite backup plugin such as BackWPup or copy the file its self

cp /var/www/html/wp-config.php /var/www/html/wp-config.php.bak

next, use your favorite text editor such as nano or vi and add the following line

define(‘WP_DEBUG’, false);

//Php Memory Limit increase
define(‘WP_MEMORY_LIMIT’, ‘256M’);
/* That’s all, stop editing! Happy blogging. */

Ensure that you put the WP_MEMORY_LIMIT directive before the That’s all line

If you are using apache you will want to run the following command to restart it.

service apache2 restart or for systemd systems systemctl restart apache2

Now if you don’t want to edit your wp-config file or don’t have access to it the next option you have is to edit your .htaccess file , in that case you will use your favorite editor but this time you will use the following directive

php_value memory_limit 256M

You can also restart the apache process for good measure.

Now of course if your site is not experiencing issues with PHP memory limits then you will not notice any difference in speeds with this tweak

If you are seeing errors in your PHP log like this

PHP Fatal error: Allowed Memory Size of 20971520 Bytes exhausted (tried to allocate 131072 bytes)

Then you are a candidate for this tweak.

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.