Discover your SEO issues

Please enter a valid domain name e.g. example.com

Increasing PHP Memory Limits in WordPress via wp-config.php

3

WordPress is a powerful and flexible content management system, but as your website grows in terms of plugins, themes, and traffic, performance issues can emerge. One common bottleneck site owners and developers encounter is the PHP memory limit. If your site is running into white screens, 500 internal server errors, or general sluggishness during tasks like importing data or running large plugins, you may need to increase your PHP memory limit, and doing so via wp-config.php is often the most direct solution.

TL;DR

If your WordPress site is experiencing memory-related issues such as blank screens or error messages, increasing the PHP memory limit can often resolve them. This can be done safely by editing your wp-config.php file and adding a line that increases the memory limit WordPress has access to. Most websites benefit from increasing the limit to 256MB. However, always ensure that your hosting provider allows for this change and monitor your site afterward for improvements.

What is the PHP Memory Limit and Why Does It Matter?

The PHP memory limit is a server-side configuration that controls how much memory a PHP script is allowed to consume. In the context of WordPress, every action—loading a theme, executing a plugin, or processing a form—relies on PHP scripts. When the memory allocated is insufficient, you may encounter fatal errors like:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 123456 bytes)

If you see a similar message, it means your current PHP memory limit is too low for what your site is trying to do.

Some of the most common symptoms of low PHP memory limits include:

  • White screen of death (WSOD)
  • 500 internal server errors
  • Broken media uploads
  • Failure during theme or plugin updates

How to Check Your Current PHP Memory Limit

Before making any changes, it’s helpful to know what your current memory limit is. There are a few ways to check:

  1. Using WordPress Site Health Tool: Go to Tools > Site Health > Info > Server. Look for the “PHP memory limit” entry.
  2. Creating a PHP Info File: Create a file named phpinfo.php and add the following code:
<?php phpinfo(); ?>

Upload the file to your server and navigate to yourwebsite.com/phpinfo.php. Look for the memory_limit directive.

Editing wp-config.php to Increase PHP Memory

The wp-config.php file is one of WordPress’s core configuration files. Located in your root WordPress directory, it controls various critical aspects of your site’s behavior. Increasing the PHP memory limit through this file is straightforward and effective.

Step-by-Step Instructions

  1. Backup Your Site: Before making any change to core files, always backup your site (database and files). Simple mistakes can cause your site to crash.
  2. Access wp-config.php: Use an FTP client like FileZilla or your hosting cPanel’s File Manager to locate and open the wp-config.php file.
  3. Edit the File: Look for the line that says /* That's all, stop editing! Happy publishing. */. Insert the following code just above it:
define( 'WP_MEMORY_LIMIT', '256M' );

This command adjusts the standard memory allowance for WordPress. If you’re performing admin-intensive tasks, you might also want to increase the memory limit for the admin dashboard:

define( 'WP_MAX_MEMORY_LIMIT', '512M' );
  1. Save and Upload: Save the file and re-upload it to your server if needed.

Understanding the Values

The values you define (like ‘256M’) indicate the limit in megabytes. Common values include:

  • 64M (default on many low-tier hosts)
  • 128M (suitable for many small to medium-sized sites)
  • 256M (recommended if using resource-heavy plugins like premium page builders)
  • 512M (usually needed for large sites with high traffic or complex operations)

Verifying Your Change

After saving your changes to wp-config.php, return to the WordPress Site Health tool or reload your phpinfo.php file in the browser. The updated PHP memory limit should now be reflected. If not, the change may be overridden by server settings or restricted by your host.

Alternative Methods for Changing PHP Memory Limit

1. php.ini File

If you have access to the server’s php.ini file, you can explicitly define the memory limit:

memory_limit = 256M

This method is often considered more authoritative since it configures memory limits on the PHP level rather than application level.

2. .htaccess File

If you’re running WordPress on an Apache server, you may also be able to define memory limits in your .htaccess file:

php_value memory_limit 256M

Note that improper use of .htaccess can result in server errors, so proceed with caution.

3. Contact Your Hosting Provider

Some shared hosting environments restrict changing PHP memory settings. In these cases, even if you modify wp-config.php, the server may override your configuration. Reach out to your hosting provider to confirm whether you can increase memory limits and how.

Best Practices and Precautions

  • Don’t allocate more than needed: More memory doesn’t always mean better performance. Excess memory use can impact overall server resources.
  • Monitor after making changes: After increasing memory limits, be sure to monitor site logs and behavior for a week to ensure no new issues arise.
  • Maintain best practices: Avoid using excessively bloated plugins or poorly optimized themes which unnecessarily consume server memory.

Troubleshooting Common Issues

Error Persists After Memory Increase

If the error continues even after you’ve increased the memory limit, double-check the following:

  • The wp-config.php change was made above the line that reads /* That's all, stop editing! Happy publishing. */
  • Your host isn’t overriding your memory settings
  • Syntax errors (a misplaced semicolon or wrong quotes) in your configuration file

500 Internal Server Error Appears

This may indicate incorrect syntax or misconfiguration in your wp-config.php or .htaccess file. Check your server’s error log for more detail or revert the recent changes to debug.

When to Consider Upgrading Hosting

If you’ve attempted to increase the PHP memory limit and still face limitations, your hosting environment may be inadequate for your site’s needs. Shared hosting often restricts memory usage to maintain server health across all tenants.

Consider upgrading to a plan that offers more resources such as VPS (Virtual Private Server) or managed WordPress hosting. These typically allow greater customization and come with higher default limits suitable for growing websites.

Conclusion

Increasing your PHP memory limit via wp-config.php is a safe and usually effective way to resolve common memory-related issues in WordPress. Whether you’re managing a modest blog or a complex eCommerce platform, ensuring your site has enough memory to operate smoothly should be a key part of your performance optimization efforts.

Always remember to backup your site before making any changes and verify with your host if you are uncertain about resource limitations. Armed with the right configuration, you can ensure your WordPress site remains stable, fast, and reliable.

Comments are closed, but trackbacks and pingbacks are open.