Skip to main content

A PHP memory limit sets the maximum amount of memory a single PHP script may allocate. If a WordPress site or another PHP application runs out of that allowance, it may show an “Allowed memory size exhausted” error, stop a request, or fail during an update or import. The right fix is to confirm the active limit, identify what is using memory, and raise the setting only when the application needs it and the hosting plan allows it.

What does a PHP memory limit control?

The PHP memory_limit directive caps the memory available to an individual PHP script. It helps prevent a script from consuming unlimited memory, although it does not represent the total RAM available to a server or guarantee that a site will use that amount. The configured value varies by PHP configuration and hosting provider, so check the value active for your site instead of assuming a universal default. See the PHP manual’s description of memory_limit.

Why memory limits matter for web hosting

When a script reaches its PHP memory limit, PHP stops that script and reports an error. Visitors may see an incomplete page, while administrators may find that a plugin update, import, image operation, or dashboard task fails. A low limit can be one cause, but inefficient code, a plugin conflict, large data sets, or a server resource cap may also be involved.

Common situations that use more PHP memory

  • Installing or updating WordPress plugins and themes
  • Running WooCommerce with several extensions or processing a large order import
  • Importing large CSV files or database records
  • Resizing high-resolution images with GD or ImageMagick
  • Running complex queries on large data sets
  • Editing large pages with a page builder

How to check your current PHP memory limit

Check the value that applies to the website and PHP version where the error occurs. A value shown in a hosting panel or configuration file may differ from the value used by a particular site.

Check WordPress Site Health

In WordPress, open Tools → Site Health → Info and expand the Server section. It reports the PHP memory limit alongside other server details. You can also check the hosting control panel, if it exposes PHP settings.

Use phpinfo() only when necessary

A temporary PHP file containing <?php phpinfo(); ?> can display the active configuration in a browser. This page reveals server configuration details, so use it only if you know how to do so safely and delete the file immediately after checking. WordPress Site Health or your hosting provider is usually a safer option.

How to increase the PHP memory limit

The method depends on your PHP handler, hosting panel, and account permissions. Back up the relevant configuration before editing it. If you are unsure which configuration file applies, ask your host to confirm the active setting and its maximum.

Change the PHP configuration

If your host allows per-site PHP configuration, use its PHP settings panel or the supported configuration file, which may be php.ini or .user.ini. A setting may look like this:

memory_limit = 256M

The number is an example, not a universal recommendation. Choose a value based on the application’s needs and the resources available in your plan, then check the active value again. On managed or shared hosting, a provider may enforce a ceiling or require support to make the change.

Use .htaccess only on supported Apache configurations

On Apache setups where PHP runs as an Apache module and the required override permissions are enabled, a directive may be accepted in .htaccess:

php_value memory_limit 256M

This does not work on every server configuration. On unsupported setups, it can cause an HTTP 500 error. Check with your host before using it; PHP documents this method for specific Apache module configurations in its configuration change guide.

Set WordPress memory constants

WordPress provides WP_MEMORY_LIMIT for normal site operations and WP_MAX_MEMORY_LIMIT for administration tasks that need more memory. Add or adjust the constants in wp-config.php before the “That’s all, stop editing!” line:

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

These example values are not recommendations for every site. WordPress may attempt to raise the PHP limit to the requested value, but the server configuration can prevent that. The PHP limit and any host-level limits still apply. See the WordPress PHP performance guidance and its notes on troubleshooting common errors.

Ask your hosting provider

If the setting does not change, or the error continues after a reasonable increase, ask your host which PHP configuration is active, what limit applies to your plan, and whether the error log identifies a script or request that is exhausting memory. A VPS can offer more control over server configuration, while managed WordPress hosting may provide WordPress-specific support. The available controls and resource limits depend on the service and plan.

How to troubleshoot a memory error

  1. Record the full error message and when it occurs, such as during an image upload or plugin update.
  2. Check the active PHP limit in Site Health or the hosting panel.
  3. Review the PHP or WordPress error log for the script named in the error.
  4. If the problem began after a change, test the relevant plugin, theme, or task in a staging site where possible.
  5. Raise the limit only if the workload needs it and the host permits it. Recheck the active value and repeat the failed task.
  6. If memory use remains unusually high, investigate the code or workload instead of continually increasing the limit.

Setting PHP memory_limit to -1 removes that PHP limit, but it does not remove operating-system, account, or other hosting limits. It can also allow a script to consume more resources than intended, so it is rarely an appropriate fix on a production website. A higher limit is a capacity setting, not a substitute for diagnosing the cause.

Choosing hosting for PHP workloads

When comparing plans, check whether you can view or adjust PHP settings, what resource limits apply, and how support handles configuration issues. If you manage a WordPress site, compare the features and support included with managed WordPress hosting. For related server tasks, see our guides to changing the PHP version in cPanel and monitoring server resources in cPanel.

Managed WordPress hosting plans and support options

Explore managed WordPress hosting

Compare WordPress hosting features, management tools, and support to see whether a managed plan fits your site.

Conclusion

A PHP memory limit controls how much memory an individual PHP script can allocate, but the active value and available adjustment depend on the server and hosting plan. Check the setting where the error occurs, investigate the script or task using memory, and make a measured change only when needed. If WordPress settings do not take effect or the error persists, ask your host to confirm the applicable limit and help identify the cause.