How to Increase PHP Memory Limits for WordPress

Share This Post:

Facebook
Twitter
LinkedIn
Reddit
Email

As a WordPress website owner or developer, you may have encountered the dreaded error message: “Fatal error: Allowed memory size of xxxxxxx bytes exhausted.” This typically means that your website has exceeded its PHP memory limit, which can lead to a poor user experience or even the crashing of your site. This article will guide you on how to increase PHP memory limits for WordPress to ensure smooth operation and improved performance.

Understanding PHP Memory Limit

PHP is the scripting language that powers WordPress and many other web applications. The PHP memory limit is the maximum amount of memory that a PHP script can consume. If your website is complex or has to handle a lot of data, it may require more memory than the PHP’s default limit.

The PHP memory limit set by your WordPress hosting provider often varies, typically between 64MB to 256MB. However, WordPress itself attempts to increase this limit to 40MB (for single sites) or 64MB (for multisite) if it’s less. Regardless, you may need to increase this limit further, especially if you use a lot of plugins or handle large amounts of data.

Increasing PHP Memory Limit in WordPress

Before you proceed, ensure you have a backup of your website. If anything goes wrong, this will allow you to restore your website to its previous state.

1. Edit your wp-config.php file

The `wp-config.php` file is one of the core WordPress files. You can increase the PHP memory limit by adding a single line of code:

define( ‘WP_MEMORY_LIMIT’, ‘256M’ );

This line sets the PHP memory limit to 256MB. If your website needs more memory, you can increase this number accordingly.

2. Modify your PHP.ini file

If editing the `wp-config.php` file doesn’t work, you can try changing the memory limit in your `PHP.ini` file. This is a default PHP file, and it controls many aspects of what your PHP installation allows.

memory_limit = 256M;

If you can’t find your `PHP.ini` file, it may be hidden, or you may not have access to it depending on your hosting provider. In that case, it’s best to contact your host’s support.

3. Update your .htaccess file

As a last resort, you can attempt to increase the PHP memory limit by modifying the `.htaccess` file located in the root directory of your WordPress installation.

php_value memory_limit 256M

Testing the Changes

After you’ve increased the PHP memory limit, it’s important to verify if the changes have taken effect. You can do this by creating a PHP info file. Alternatively, many WordPress plugins can help you monitor server configurations and values.

Increasing the PHP memory limit can greatly improve your WordPress website’s performance. However, it’s crucial to remember that allocating too much memory to PHP can potentially exhaust your server resources and lead to other issues. Therefore, it’s a matter of balance and understanding the specific needs of your website.

Also, if you’re consistently exceeding the PHP memory limit, it may indicate underlying issues with your plugins, theme, or custom code. It’s recommended to analyse your site’s performance and make necessary optimisations.

Remember, always consult with a web development or IT professional if you’re unsure about making these changes. Your website is a vital asset, and any errors can significantly affect its functionality.

LinkedIn | Portfolio 

Lewis Sweeney

Freelance Web Developer

I’m a freelance web developer based in Manchester, England and I build and fix websites all day every day. I specialise in WordPress, WooCommerce and Shopify sites so whether you’re looking for a brand new site build or have bugs on your existing one get in touch…