Increasing the PHP memory limit in WordPress is a way to give your site’s PHP scripts more server memory, which fixes the “Allowed memory size exhausted” fatal error. You can raise it in wp-config.php, php.ini, .htaccess or your hosting control panel, and 256M is enough for most sites.
A common PHP error in WordPress is the memory limit error, which appears as:
Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in /path/to/file.php on line Z.
This happens when WordPress exceeds the allocated PHP memory limit, often due to heavy plugins, themes, or scripts.
Increasing the memory limit in wp-config.php or php.ini usually fixes it.
What is PHP memory limit?
The PHP memory limit is the maximum amount of server memory a single PHP script can use while it runs. WordPress is built using PHP, a popular server-side programming language. Your hosting provider sets a default amount of memory to help prevent overuse of server resources. The default PHP memory limit set by hosting providers varies based on the hosting environment and the specific hosting plan.
In shared hosting environments, it’s common to see default PHP memory limits ranging from 32 MB to 128 MB.
Why WordPress runs out of memory?
If your website requires more memory due to the following reasons, you may need to increase the PHP memory limit to prevent PHP fatal errors like the “Allowed memory size exhausted” message. The most common causes of high memory use are listed below.
- Resource-Intensive Plugins or Themes: Some plugins (like page builders, SEO tools, or eCommerce plugins) require more memory to function properly, especially when they handle large amounts of data or complex tasks.
- Large Media Files: Uploading and managing large images, videos, or other media files can consume a lot of memory, particularly when they are processed or resized.
- Complex or Custom Code: If your site uses custom-built features, complex themes, or specialized code, it may require more memory to execute efficiently.
- Heavy Database Queries: Sites with large databases or complex queries may run out of memory if the server can’t handle the load of retrieving and processing large amounts of data.
- WordPress Updates and Maintenance: Certain WordPress updates, especially when updating the core, themes, or plugins, may require additional memory to complete without errors.
How to check your current PHP memory limit
You can see your current limit in the dashboard without editing any files. Go to Tools › Site Health, open the Info tab and expand the Server section. The PHP memory limit row shows the limit currently in effect for your site. If you also see PHP memory limit (only for admin screens), that’s the higher limit WordPress uses in the dashboard.

Then expand the WordPress Constants section. WP_MEMORY_LIMIT is the limit WordPress requests on every page load, and WP_MAX_MEMORY_LIMIT is the higher limit it requests for dashboard screens, image processing and WP-Cron (256M by default, or your server’s limit if that’s higher).
WordPress raises PHP’s memory limit to these values when the server allows it, but some hosts lock it. If the value in the Server section doesn’t change after you edit wp-config.php, use one of options 2–4 below.
Come back to this screen after each change to confirm the new value is in effect.
How to increase PHP memory limit
By default, WordPress tries to raise the PHP memory limit to 40 MB on a single site and 64 MB on multisite if your server sets it lower. However, that is often not high enough for most modern themes and plugins.
You can edit the files mentioned in option 1, option 2, and option 3 using an FTP client such as FileZilla, or File Manager of your WordPress hosting provider. Make sure to backup the file before attempting to edit.
Option 1: wp-config.php file
Option 1 is the quickest fix, because WordPress reads this setting on every page load. wp-config.php is found at the root folder of your website where WordPress core files are located. Usually, this will be the public_html folder. Paste the following line just before the one that says /* That's all, stop editing! Happy publishing. */:
define( 'WP_MEMORY_LIMIT', '256M' );Save the file and check your WordPress website.
Increase the memory to 512M or more if you continue to see the memory exhausted error.
Option 2: php.ini or .user.ini file
php.ini and .user.ini are configuration files used to set PHP settings on a server, such as memory limits, upload sizes, and execution time, allowing you to customize PHP behavior for your website. Common options include memory_limit, upload_max_filesize, post_max_size, max_execution_time, and max_input_vars.
We recommend asking your hosting provider which .ini file is being used for PHP configuration and where it is located. Typically it’s located in your root directory.
memory_limit = 256MCheck your website.
If necessary, restart your web server (Apache, Nginx, etc.) for the changes to take effect.
Option 3: .htaccess file
Defining PHP values in .htaccess file may cause HTTP 500 error on some of the hosting providers. If that happens, revert the changes and try the other options. .htaccess is located at your root folder. Add the following code before the line that says # END WordPress.
php_value memory_limit 256MOption 4: PHP options at your hosting control panel
This option depends on the type of control panel that you’re using. If you are using cPanel, use the MultiPHP Manager, found in the Software section. Most control panels let you change the memory limit without editing any files, which makes this the safest option if you’re not comfortable with FTP.

Select the domain that you want to make changes to.

You can then set the memory limit to 256M or more.

How to avoid WordPress memory exhausted error
Raising the memory limit fixes the error, but lowering how much memory your site uses keeps it from coming back after the next plugin update or large import. Following best practices should reduce the memory consumption of your WordPress website.
- Update plugins or themes one by one, manually, rather than updating them at the same time.
- Deactivate unused plugins.
- Optimize images before uploading to WordPress media. Use WebP or AVIF formats for best file size and quality. Alternatively, use an image optimizer plugin that does this optimization and conversion automatically.
- Use a lightweight theme such as GeneratePress or Hello Elementor
- Use a caching plugin. Caching reduces the load on your server and decreases the memory usage by storing static versions of pages.
- Regularly clean up and optimize your database. Plugins like WP-Optimize can do this properly.
- Monitor server logs for any fatal errors that are caused by PHP memory limit. Usually, your log file will be
error_loginside the root folder.
Seeing a different error? See our guide to common WordPress errors and fixes.




