WEB HOSTING

cPanel : How to Fix the “Allowed Memory Size of Bytes Exhausted” cPanel Fatal Error

“Allowed memory size of bytes exhausted” error in cPanel usually indicates that your PHP script has exceeded the allocated memory limit. This is a common issue, especially with resource-intensive applications like WordPress. Fortunately, there are several straightforward methods to resolve this error.

Understanding the Error

The error message typically looks like this:

PHP Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 32768 bytes)

This means your script attempted to use more memory than PHP allows. To fix this, you can increase the PHP memory limit or identify and address the root cause.

Step-by-Step Solutions

1. Increase PHP Memory Limit via cPanel’s MultiPHP INI Editor

In your cPanel account, you can adjust the PHP memory limit using the MultiPHP INI Editor:

  1. Log into your cPanel account.
  2. Navigate to Software > MultiPHP INI Editor.
  3. Select your domain from the dropdown menu.
  4. In the Basic Mode tab, locate the memory_limit setting.
  5. Increase the value (e.g., 256M or 512M).
  6. Click Apply to save the changes.

For detailed instructions, check this guide.

Note: Adjusting the memory limit here affects all scripts running under the selected PHP version.

2. Modify the wp-config.php File (For WordPress Users)

For WordPress sites, you can increase the memory limit by editing the wp-config.php file:

  • Access your website files via cPanel’s File Manager or an FTP client.

cPanel File manager

  • In the root directory (usually public_html)

public_html

  • Locate the wp-config.php file

wp config

  • Edit the file and add the following line above the line that says /* That’s all, stop editing! Happy blogging. */

define(‘WP_MEMORY_LIMIT’, ‘256M’);

  • Save the changes and check if the error persists.

Note: This method sets the memory limit for WordPress specifically and may not affect other PHP applications.

3. Edit the .htaccess File

If you don’t have access to the php.ini file, you can increase the memory limit via the .htaccess file:

  • In the root directory (public_html), locate the .htaccess file.

If you can’t see the .htaccess file, check this guide to learn how to display the hidden files.

  • Edit the file and add the following line:

php_value memory_limit 256M

  • Save the changes and test your website.

4. Modify the php.ini File

If you have access to the php.ini file:

  • Locate the php.ini file in your server’s root directory.
  • Edit the file and find the memory_limit directive.
  • Increase its value, for example:

memory_limit = 256M

  • Save the file and test your website.

Note: Changes to php.ini affect all PHP applications on the server.

5. Disable Plugins (For WordPress Users)

Sometimes, a faulty or resource-intensive plugin can cause memory exhaustion:

  1. Access your website files via cPanel or FTP.
  2. Navigate to wp-content and rename the plugins folder to plugins-deactivated.
  3. Check if your website loads without errors.
  4. If it does, rename the folder back to plugins and reactivate your plugins one by one via the WordPress dashboard to identify the culprit.

Note: Always ensure you have backups before deactivating plugins.

6. Optimize Your Code and Resources

If increasing the memory limit doesn’t resolve the issue, consider optimizing your website:

  • Reduce Plugin Usage: Deactivate and delete unnecessary plugins.
  • Optimize Themes: Use lightweight themes without excessive features.
  • Implement Caching: Use caching mechanisms to reduce server load.
  • Optimize Databases: Regularly clean and optimize your database tables.

Note: Efficient coding practices can significantly reduce memory usage.

Final Thoughts

The “Allowed memory size of bytes exhausted” error is typically resolved by increasing the PHP memory limit or optimizing your website’s resources. Always ensure you have recent backups before making changes to your website’s configuration. If the issue persists after trying the above methods, consider reaching out to our support for further assistance.


Articles Liés