Your WordPress site suddenly shows a white page, a critical error, or a message that looks like this:

Fatal error: Allowed memory size of 268435456 bytes exhausted 
(tried to allocate 20480 bytes) in /home/ton-site/wp-includes/...

The number changes from one site to another (134217728, 268435456, 536870912 depending on your current limit), but the message is always the same: PHP no longer has enough memory to run what your site is asking of it. On recent versions of WordPress, you will sometimes only see “There has been a critical error on your website”, it’s the same cause hidden behind a more polite message.

It almost always happens at the worst moment: while installing a plugin, a WooCommerce import, uploading a heavy image, or just after an update. The server hits its ceiling and stops dead.

I’ve been doing WordPress maintenance for over 10 years and this error comes up every week on at least one site. In 90% of cases, it’s fixed in under 10 minutes once you know where to look. In the remaining 10%, a plugin is running in a loop and the problem is elsewhere. This guide covers both.

Fix the allowed memory size exhausted error in 3 minutes

  1. Check your current memory limit (Tools > Site Health > Info > Server)
  2. Increase the value according to your host (o2switch, OVH, other)
  3. If the error comes back despite enough memory, a plugin is the cause

In the vast majority of cases, step 2 is enough. The full guide is below.

Start by checking your current memory limit

Before changing anything, look at what your server already allocates. In your WordPress dashboard, go to Tools > Site Health > Info, then expand the Serversection. Look for the line PHP memory limit.

If you see 64M or 128M, you’ve found your problem. If you already see 512M or more and the error persists, memory is not the cause. A plugin is probably running in a loop and consuming everything you give it, whatever the value. In that case, jump straight to the section “When increasing the memory is not enough”.

To give you a benchmark, here are the values suited to your setup. These values assume you are running PHP 8.1 or higher. If you’re still on PHP 7.4, expect about 20 to 30% more memory consumed for the same site. That’s a good reason to update PHP if you haven’t done so yet.

Type of setupRecommended memory
WordPress + lightweight theme256M
WordPress + WooCommerce512M
WordPress + page builder (Elementor, Avada, Divi…)512M
WooCommerce + page builder1024M minimum
WooCommerce + page builder + heavy third-party plugins1024M to 2048M

Increase PHP memory according to your host

The method to use depends directly on your host. Not all methods work everywhere, and some are simply ignored depending on the server configuration. Here is what really works, host by host.

o2switch: Select PHP version in cPanel

This is the most reliable method on o2switch, and it’s the one I use systematically on the client sites I maintain with this host. From your cPanel, type Select PHP Version in the search bar at the top or find it in the Software section. This setting will apply to all the domains of the hosting account. In the Options tab, change the memory_limit value according to the table above.

Increase memory_limit via Select PHP Version cPanel o2switch

The change is immediate, no need to clear the cache or restart anything. To check it has been applied, go back to Tools > Site Health > Info > Server in your WordPress. The PHP memory limit line should show the new value.

o2switch note: the default limit is 512M on most plans. You can go up to 2 GB by contacting o2switch support directly, if your setup requires it.

OVH / OVHcloud: a limit set by the host

On OVH shared hosting, you don’t choose the memory limit yourself. OVH states that the php.ini file cannot be modified on its web hosting plans and that the PHP configuration is shared across its entire shared infrastructure.

The .ovhconfigfile, at the root of your hosting, is only used to choose the PHP version, the PHP engine, the environment (production or development) and the server image. A php.memory_limit line added to this file has no effect.

If your plan’s limit is not enough, start by looking for the plugin that consumes too much (see below). If your site really needs more, you have to move to a more powerful plan: ask OVH support for the limit of each plan.

Good to know: the OVH documentation on the .ovhconfig file lists all possible settings. Check it before following a tutorial that tells you to add memory lines in this file.

Other hosts: the .user.ini file

If your host doesn’t offer a dedicated interface, the universal method on shared hosting is the .user.inifile. Create this file at the root of your site (where wp-config.php is located) and simply add:

memory_limit = 256M

This file is read directly by PHP in CGI/FastCGI mode, which is the standard configuration of all shared hosts. The change takes effect within a few minutes.

For other common hosts:

  • Hostinger : hPanel > Advanced > PHP Configuration, edit memory_limit directly.
  • Infomaniak : admin panel > Web Hosting > PHP > Configuration.
  • SiteGround : Site Tools > Devs > PHP Manager, PHP Variables tab.

wp-config.php: as a complement only

You’ll often find this solution first in tutorials. It consists of adding to wp-config.php:

define('WP_MEMORY_LIMIT', '256M');

What this line really does: it tells WordPress how much memory it can request from PHP. But PHP cannot exceed the limit your server imposes. If your host limits it to 128M and you put 256M in wp-config.php, WordPress will see 256M in its internal settings but PHP will keep stopping at 128M.

It is therefore useful as a complement to a server-side change, to make sure WordPress uses all the available memory. But it doesn’t replace the methods above.

To also increase the memory in the WordPress admin (useful notably during WooCommerce imports), add below:

define('WP_MAX_MEMORY_LIMIT', '512M');

When increasing the memory is not enough

I regularly work on sites where the client has already raised the memory to 1024M, or even 2048M, with no result. The error keeps coming back. In those cases, it’s not a limit problem: it’s a plugin or script running in a loop and consuming everything you give it, whatever value is configured.

To identify the culprit, the method is simple:

  1. Deactivate all your plugins by renaming the folder via SFTP.wp-content/plugins to plugins-off
  2. Reload your site. If the error disappears, a plugin is the cause.
  3. Put the original folder name back, then deactivate the plugins one by one from the admin until you find the culprit.
  4. If the error persists even without plugins, test with a default WordPress theme (Twenty Twenty-Four).

To speed up the diagnosis, enable the WordPress logs and check the file wp-content/debug.log. You’ll see exactly which file triggers the error and on which line. My guide on how to find WordPress logs explains how.

Remember: raising the memory to 2048M without finding the cause is like putting more fuel in a leaky tank. It fixes nothing in the end.

If your site shows another error message, I also explain how to fix the Maximum execution time exceeded error and the 413 Request Entity Too Large error.

To go further, you can consult the WordPress page on the most common errors (in English).

Should you change host or plan?

If you have to raise PHP memory to 2 GB just to make a WordPress site work, and the error still comes back regularly despite that, the problem is no longer memory. Three leads to examine in this order:

  1. Audit your plugins. A poorly coded plugin can saturate a properly sized server on its own. It’s the most frequent case I come across in maintenance.
  2. Check your PHP version. A site on PHP 7.4 consumes noticeably more than a site on PHP 8.2 or 8.3. Updating is often the first lever before changing host.
  3. Only then, look at your host. If you’re on low-cost shared hosting and your site is an active WooCommerce store, you may have reached the plan’s structural limits. In that case, moving to a plan with more allocated resources (o2switch’s Cloud, for example) will solve the problem at the root.

In short: before paying more, check what is really consuming memory on your current site.

Is your site still showing an error?

If the error persists despite the steps in this guide, it is often a sign of a deeper problem (faulty plugin, corrupted theme, malicious script). I work remotely to identify the exact cause and get your site back online.

Describe your problem →

And if you want to avoid going through this kind of situation at every update, take a look at my WordPress maintenance. That’s exactly why it exists.

Preventing the error from coming back

Once the error is fixed, a few habits to avoid it coming back:

  • Limit the number of active plugins. Each plugin adds weight. Deactivate the ones you don't really use.
  • Optimise your images before uploading them. Uncompressed images consume a lot of memory when PHP processes them. A tool like Squoosh or a plugin like Imagify does the job.
  • Update PHP. Versions below 8.0 consume noticeably more memory than recent versions. See my guide to update PHP on WordPress.
  • Clean your database regularly. A database weighed down by revisions, expired transients or plugin logs can cause memory spikes at load time.
  • Watch your updates. A failed plugin or theme update is often the trigger for the first appearance of this error.

Frequently asked questions

memory_limit is the limit set at the PHP server level. It’s the real ceiling. WP_MEMORY_LIMIT in wp-config.php is the value WordPress asks PHP to use. If you put 512M in wp-config.php but your server is capped at 256M, PHP will stop at 256M. The server limit always wins. That’s why changing only wp-config.php isn’t enough in many cases.

If memory is sufficient for your type of setup (see table above) and the error persists, a plugin or script is running in a loop and consuming everything allocated to it. Deactivate your plugins one by one to identify the culprit, and check the WordPress logs to see which file triggers the error.

It depends on your host. On some hosts, WordPress can indeed push the PHP limit via wp-config.php. On others (like o2switch with LiteSpeed), the server limit takes precedence and wp-config.php has no effect on the real limit. The recommended method remains to change the limit directly on the server side (Select PHP Version on o2switch, .user.ini at other hosts) and to add wp-config.php as a complement.

Yes. When PHP runs out of memory, it stops dead and your site may show a white page instead of an error message. See my article on the WordPress white screen if that’s what you’re seeing.

Not by editing .ovhconfig: this file only manages the PHP version and environment. On OVH shared hosting, the limit is set by the host. At other hosts, here are benchmarks from my experience, not official rules: 256M for a standard WordPress site, 512M with WooCommerce or a page builder, 1024M for WooCommerce with a heavy page builder.

Technically yes on Apache, with the directive php_value memory_limit 256M. But if your host uses LiteSpeed (which is the case for o2switch), this directive is silently ignored without causing an error. Always prefer the Select PHP Version method (o2switch) or .user.ini depending on your host.

Stuck on this step?

Contact me and I'll help you out. I've been supporting website owners for more than 10 years now:

About the Author: Jennifer
Fix the "Allowed memory size exhausted" error on WordPress
I'm Jennifer, founder of Webooste and a freelance WordPress developer based in Marseille, France, since 2019. I hold a French state-certified diploma in web and mobile web development and have over 10 years' experience in digital. I look after the maintenance and security of WordPress websites and WooCommerce shops, 100% online, with clients worldwide. I hunt down bugs, chase away malware and take the technical worries off your mind! See my maintenance plans · Get in touch Find me on LinkedIn, Instagram, TikTok, YouTube or WhatsApp.