How to increase the WordPress memory limit: wp-config and PHP settings
· The AYT team · 5 min read

You increase the WordPress memory limit in two places: first memory_limit in the server's PHP settings (the real ceiling), then, if needed, the WP_MEMORY_LIMIT constant in wp-config.php. WordPress can request at most what PHP allows, so if you only change wp-config.php and the server enforces a lower limit, nothing changes.
What the problem looks like
The classic sign is an error like this:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)
The large number is the limit in bytes: 134217728 is 128 MB. You usually don't see this text on the site. You see WordPress's "There has been a critical error on this website" or a blank page instead, and the full error lands in the server's error log. It shows up mostly during heavy operations: imports, generating thumbnails for large images, a page builder's editor, updates, WooCommerce reports.
The two limits
memory_limit (PHP) is the most memory a single PHP script may use. The server sets it, and you can change it from your hosting panel.
WP_MEMORY_LIMIT (WordPress) is the memory WordPress tries to request for the site's pages. The default is 40 MB on a single site and 64 MB on Multisite. WordPress only raises PHP's limit up to this value and never lowers it: if PHP already has 256 MB, the site gets 256 MB.
WP_MAX_MEMORY_LIMIT is the same thing for the admin area and the heavy operations in it (image processing, for example). The default is 256 MB.
The WordPress documentation says plainly that some hosts don't allow the PHP limit to be raised automatically. In that case the constants in wp-config.php have no effect, and memory_limit has to be changed in the server settings.
Step 1: check the real limit
In wp-admin, under Tools → Site Health → Info:
- in the Server section, "PHP memory limit" is PHP's limit;
- in the WordPress Constants section you see
WP_MEMORY_LIMITandWP_MAX_MEMORY_LIMIT.
If wp-admin no longer opens, read the value in your hosting panel, in the domain's PHP settings.
Step 2: raise PHP's memory_limit
Where you can change it, in the order that works most reliably:
- In your hosting panel, in the domain's PHP settings (php.ini) editor.
- In a
.user.inifile in the site's main folder, on servers running PHP-FPM:
memory_limit = 256M
- In
.htaccess, withphp_value memory_limit 256M, only on Apache with PHP running as a module. On PHP-FPM this line causes a 500 error.
After the change, check in Site Health that the new value shows up. .user.ini is reread periodically (every 5 minutes by default), so it can take a moment.

Step 3: set the constants in wp-config.php
If PHP's limit is high but WordPress still reports a memory shortage (for example a plugin reads WP_MEMORY_LIMIT and complains), add this to wp-config.php, above the line /* That's all, stop editing! */:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
Use values no higher than PHP's memory_limit. A value above what the server allows doesn't cause an error, but it doesn't bring any extra memory either.
Which WordPress memory limit to pick
For a brochure site with a few plugins, 128 MB is usually enough. WooCommerce's server recommendations ask for a WordPress memory limit of at least 256 MB. Go above 512 MB only if a specific operation (a large import, a report) really needs it, and only after checking it isn't a plugin problem.
On a hosting account with a fixed amount of RAM, each PHP process can take up to memory_limit, so a higher limit means fewer PHP requests can run at the same time. A 1 GB memory_limit "just in case" can make the site slower under heavy traffic.
When raising it doesn't help
If the error comes back after every increase, the memory use isn't normal and you need to find the cause:
- deactivate plugins one at a time and watch memory use; the free Query Monitor plugin shows how much memory each page uses;
- look in the error log for the file named in the error message: the path (
wp-content/plugins/plugin-name/...) usually tells you the culprit; - images uploaded straight from a phone or camera, at tens of megapixels, need a lot of memory to generate thumbnails; scale them down before uploading;
- large imports (products, users) are safer in batches.
If the site only shows "critical error" and you don't know where it comes from, the guide to the WordPress 500 error walks you through the diagnosis. If the error appears when uploading a file, read how to fix "The link you followed has expired" as well.
Frequently asked questions
Can I set memory_limit = -1?
Technically, -1 means no limit. Don't do it on a public site: one faulty script can eat all of the account's memory and block every other request.
Is it the same as my hosting plan's RAM?
No. The plan's RAM is the account's total memory. memory_limit is how much of it a single PHP process may take.
On AYT hosting
On AYT you change memory_limit for each domain on the panel's PHP settings (php.ini) page, and you set the memory constants in wp-config.php from the WordPress Toolkit. The number of PHP requests that can run in parallel is the account's memory divided by memory_limit, so you pick the value knowing the trade-off. If PHP runs out of memory, you get an email alert, and the panel's usage graphs show how much the account uses. Plans differ in RAM and CPU; you'll find them on the WordPress hosting page.
