It happens to all WordPress site owners and administrators eventually: The dreaded WordPress memory error.
You’re minding your own business adding new content or media to your site when suddenly a message pops up: “Fatal error: Allowed memory size of xxxxxx bytes exhausted.”
So what just happened? Why did WordPress run out of memory?
Put simply, it comes down to the programming language PHP. WordPress sites use a default memory limit for PHP code which can be exceeded as you start adding more media-rich and interactive elements to your site.
In this piece, we’ll break down what the WordPress PHP memory limit is, why it matters for your site, and what you can do to increase it.
Download Now: How to Launch a WordPress Website
[Free Guide + Checklist]
What is PHP in WordPress?
PHP is a server-side language used by WordPress to create and manage the HTML pages that make up your site. It’s called “server-side” because it operates in the WordPress backend, not on your desktop computer or mobile device.
PHP is a lightweight, speedy, and open-source language that’s ideal for generating website elements. Experienced programmers can customize or modify PHP frameworks to suit specific website needs, and the code is regularly updated to streamline functionality and enhance security. As a result, it’s an ideal general-purpose scripting language for WordPress.
What is the PHP memory limit in WordPress?
By default, WordPress has a PHP memory limit of 32MB. That’s fine for sites with few pages and a limited amount of multimedia content and plugins, but the more you add to your site the closer you get to the maximum memory limit.
When this limit is reached — let’s say you’re uploading a new video or interactive web element — WordPress will automatically increase available memory to 40MB. If you still hit the limit, you’ll get the error message described above and won’t be able to add new content until you resolve the issue.
What’s causing the PHP memory problem?
While it is possible to increase the available PHP memory in WordPress beyond 40MB, it’s worth pinpointing the cause of memory max-outs before taking action to up your limit. Here’s why: If the root cause of your memory issue isn’t simply available space but something tied to other elements on your site, adding more memory is only a temporary fix — the problem will persist and you’ll keep getting the same error.
Some possible causes of memory limit issues include:
1. Poor-Quality Plugins
Not all plugins are created equal. Some are built for speed and quality, while others are designed to perform a specific function but don’t make any effort to improve efficiency. Using multiple plugins with high memory requirements can max out available PHP memory and cause your page to suffer a fatal error.
2. Outdated PHP Versions
As noted by Search Engine Journal, 61.6% of WordPress sites are running outdated versions of PHP. Not only does this present a security risk for sites but it also impacts their performance. Newer versions of PHP are capable of handling more tasks, more quickly, in turn reducing the amount of memory in use at any given time.
3. Memory-Hungry Media
What you put on your site matters for memory. For example, if your WordPress site is largely composed of text with the occasional image and link, you probably won’t hit the memory limit. If you’re consistently uploading videos and other interactive content, you may find yourself running out of room.
What if you’re not sure what’s causing the problem? Get a plugin like Server IP and Memory Usage Display that tracks the memory usage and total available memory of your WordPress installation and shows the version of PHP you’re currently running. Visual cues highlight increasing memory usage — as memory usage ramps up, the percentage value slowly changes to red, letting you know you’re reaching the limit. The plugin also shows how much memory other plugins are using to help you pinpoint memory thieves.
But, should you maximize your memory bandwidth and push WordPress to its limit? Or, is it better to stay below the memory limit for better site performance? Let’s discuss in the section below.
What is the recommended PHP memory limit in WordPress?
WordPress has a 32MB memory limit by default, but some hosting providers increase this to 64MB for all customers. It’s also possible to go even bigger — all the way up to 256MB.
While scaling allows more room for content and media, it does come with the potential drawback of slower site speeds if you implement a host of data-heavy elements. Best bet? Try to land somewhere in the middle to balance memory throughput and performance.
How to Increase the PHP Memory Limit in WordPress
If you’ve updated your PHP, removed poor-quality plugins, cleaned up your content, and you’re still getting memory errors, you may need to increase the memory limit.
There are several ways to accomplish this goal:
Edit your wp-config.php file.
Edit your PHP.ini file.
Edit your .htaccess file.
Use a memory increase plugin.
Contact your hosting provider.
1. Edit your wp-config.php file.
If you’re reasonably confident in your tech skills, you could try editing your wp-config.php file.
First up? Getting to it. Use a file transfer protocol (FTP) or SSH file transfer protocol (SFTP) service to connect with and access your WordPress files. Your mileage will vary depending on the solution you use, but you should see something like this:
WordPress PHP Memory Limit
Open the wp-config.php file and search for this text string: define(‘WP_MEMORY_LIMIT’, ’32M’);
Then, modify it to read define(‘WP_MEMORY_LIMIT’, ‘128M’); You can go as high as 256MB, but in most cases, you won’t need this much memory.
2. Edit your PHP.ini file.
If editing your config file doesn’t solve the problem, you can also try modifying your PHP.ini file. Worth noting? Since this file governs server settings, you won’t be able to modify it if you’re using a shared hosting provider.
Look for the line memory_limit = 32M and again change it to read 128M. It’s also a good idea to modify the max_execution_time line. This line specifies the amount of time in seconds allotted for a PHP script to run. If the time limit is exceeded, PHP returns an error. Increasing this number gives your scripts more time to run, which is a good idea if you’re planning to use more memory-intensive services and plugins.
3. Edit your .htaccess file.
Your last file editing resort is the .htaccess file. While it is accessible via the directory and file list returned by FTP connections, the “.” in front means that it’s a hidden file. If you don’t see it, check to make sure your FTP or SFTP solution is set to display all hidden files and directories.
Once you’ve accessed the file, find this line: php_value memory_limit Then, add the value you want — 64M, 128M, or 256M — and save the file.
Regardless of the file editing method you choose, make sure to clear your cache before checking to see if the problem is resolved.
4. Use a memory increase plugin.
Another option to increase your available PHP memory is through the use of a plugin, such as the WordPress WP Memory Limit, Memory Usage, Server Memory, and Health plugin. This plugin works with WordPress version 5.2 or higher and lets you modify available PHP memory without the need to access or modify files.
5. Contact Your Hosting Provider
Last but not least? Contact your hosting provider and ask them to increase your WordPress PHP memory limit. Depending on the type of hosting you have — shared, dedicated, or virtual private server — this may be a quick fix or it may not be a service offered.
Thanks for the Memories
PHP memory errors in WordPress are frustrating, but they aren’t permanent. By modifying your WordPress files, using a plugin, or contacting your hosting provider, it’s possible to significantly increase your available memory and avoid PHP problems.