Fix the PHP Memory Limit Exhausted Error

Summarize with:
Share:

Encountering the “Allowed memory size of x bytes exhausted” error can bring your website to a halt and cause significant frustration. This common PHP issue means a script on your site tried to use more memory than your server’s configuration allows. Fortunately, you can resolve this error quickly. This guide provides clear, actionable methods to increase your PHP memory limit and get your website back online.

What Causes the PHP Memory Exhausted Error?

At its core, this error is a safeguard. Your web hosting environment allocates a specific amount of server memory (RAM) to run PHP scripts which power your website’s applications like WordPress or Magento. When a process demands more memory than this predefined limit, PHP stops the script and reports the error to prevent a single process from crashing the entire server. Common causes include inefficient plugins, complex database queries, or processing large media files.

How to Fix the Allowed Memory Size Exhausted Error

You can typically fix this error by increasing the memory allocated to PHP. Below are three common methods to adjust this setting. We recommend starting with the first method and proceeding to the next if it does not resolve the issue or is not applicable to your hosting environment.

Method 1 Edit Your .htaccess File

For many web hosting plans, the .htaccess file provides a simple way to override server settings. This file is a powerful configuration file for the Apache web server. A small modification here can increase your memory limit.

  1. Connect to Your Server Use an FTP client or your hosting control panel’s file manager to access your website’s files.
  2. Locate the .htaccess File Navigate to the root directory of your website (often public_html). The .htaccess file is located here. If you cannot see it, ensure your file manager is set to show hidden files.
  3. Add the Directive Before making any changes, it is wise to download a backup of the file. Open the file for editing and add the following line to the bottom. This directive tells PHP to increase the memory limit.
    php_value memory_limit 256M
    Note The value ‘256M’ is an example. You can set it to 128M, 512M, or another value depending on your needs.
  4. Save Your Changes Save the file and re-upload it to your server if necessary. Visit your website to see if the error is gone.

An alternative directive you may see is RLimitMem max. This is an Apache directive that sets the maximum memory for all processes spawned from it, which can also resolve the error but is less specific than the php_value method.

Method 2 Modify the php.ini File

The php.ini file is the main configuration file for PHP. If you have access to it, editing this file is the most direct way to change the memory limit. Access to this file is common on VPS and dedicated server plans but may be restricted on shared hosting.

  1. Find Your php.ini File The location can vary. If you have shell access, you can run php –ini to find its location. In some control panels, you may find a “MultiPHP INI Editor” or similar tool.
  2. Edit the memory_limit Directive Open the file and search for the line that contains memory_limit. It might look like this
    memory_limit = 64M
  3. Increase the Value Change the value to a higher number, such as 256M or 512M.
    memory_limit = 256M
  4. Save the File After saving the file, your web server may need to be restarted for the changes to take effect.

Method 3 Use a Control Panel Tool

Modern hosting control panels often provide a user-friendly interface to change PHP settings without editing files manually. If your hosting uses cPanel with CloudLinux, there is a straightforward tool for this purpose. This is often the safest and easiest option.

You can use the “Select PHP Version” tool in cPanel to access PHP options and change the memory_limit value directly from a dropdown menu. For a detailed walkthrough, see our guide on how to increase PHP memory limit via CloudLinux.

When Increasing Memory Is Not a Permanent Solution

While increasing the memory limit provides an immediate fix, repeatedly encountering this error suggests a deeper issue. It could mean your website’s resource demands are consistently exceeding what your current hosting plan can provide. This is a clear signal that you may have outgrown your environment.

Instead of just raising the limits, it is crucial to investigate the root cause. You should estimate hosting resource needs to understand if your CPU, RAM, and storage are still adequate. If your website’s traffic or complexity has grown, your resource requirements have likely grown with it.

For businesses running on shared hosting, this error often marks the point where an upgrade is necessary. A comparison of Shared vs VPS Hosting can clarify the benefits of a more powerful environment. If you need guaranteed resources and greater control, consider an upgrade to VPS hosting. For high-traffic sites or resource-intensive applications, our dedicated server hosting provides the ultimate performance and reliability.

Frequently Asked Questions

Here are answers to some common questions about the PHP memory exhausted error.

What is a good PHP memory limit?

For a modern content management system like WordPress, a limit of 128M or 256M is a reasonable starting point. E-commerce platforms or sites with many complex plugins may require 512M or more. The ideal value depends entirely on your specific website’s needs.

Can a WordPress plugin cause this memory error?

Yes, absolutely. A poorly coded plugin, or one performing a resource-intensive task like creating a large backup or processing images, is one of the most common causes of PHP memory exhaustion in WordPress.

How do I check my current PHP memory limit?

The easiest way is to use a PHP info file. Create a new file named phpinfo.php in your website’s root directory, add the code <?php phpinfo(); ?>, and save it. When you visit this file in your browser, you can search the page for the “memory_limit” directive to see its current value. Remember to delete this file after you are done for security reasons.

Is increasing the memory limit always safe?

Increasing the limit is generally safe, but setting an excessively high value on a shared server can affect other users. It is also important to understand that a higher limit can mask underlying code inefficiencies. It fixes the symptom but not always the root cause.

What if I do not have access to php.ini or .htaccess?

If your hosting provider restricts access to these files and does not offer a control panel tool to adjust the limit, you will need to contact their support team. They can either increase the limit for you or advise you on the necessary steps to upgrade your plan for more resources.

© 2025 All Rights Reserved. HostingB2B

Hosting B2B LTD is a Company registered in Cyprus with Company number HE410139 and VAT CY10410139C

Contact Info

© 2025 All Rights Reserved. HostingB2B