Skip to content

How to Fix – Fatal Error Allowed Memory Size Exhausted

This is the most common issue often encountered while using shared hosting plans such as WordPress, Moodle, and Jooml. In this post, we will show how to fix this within minutes.
Reading Time: 5 minutes
Fatal Error Allowed Memory

A common error with Open Source Software like WordPress, Moodle, and Joomla is in PHP “Allowed memory size error.” 

“The system has encountered an error where the amount of memory being used by the PHP script exceeds the maximum limit set by the server’s configuration. Recommendations to resolve this include increasing the memory limit in the php.ini file or optimizing the code to reduce memory usage.”

Increasing the memory limit is an easy solution. This memory_limit can be changed in the php.ini in thepublic_html folder in your hosting account. This error can creep up on your website during the normal development process. The following is an example of the error:

This is due to PHP variable data being stored in the memory that is not cleared while the PHP scripts are running.

Table of Contents

Fixing “Allowed memory size Error”

In Cpanel

The PHP memory resource can be increased in the php.ini located in the public_html. The following steps will explain how to set the php.ini to allow a larger amount of memory use (Applied Only On Cpanel Linux Hosting).

 

  1. Login to your cPanel
  2. Go to the File Manager. Select the Webroot (public_html) directory and click Go.
  3. Find the php.ini file in the public_html.

    Note! If you do not have a php.ini in your public_html files, you can create a new php.ini to your public_html directory.

    Open the php.ini with the code editor.

  4. Find / Add the following section in the php.ini file.

    max_execution_time = 30
    max_input_time = 60
    memory_limit = 128M

Try to increase the memory_limit value to 256M.

If the PHP memory_limit is already at 256M, you can increase it to 512M. Save the changes.

In order for your memory limit to take effect, you will need to make the php.ini recursive.

make php.ini recursive

[su_code]

Making your php.ini file affect all child folders as well is referred to as making the file “recursive”.

To make your public_html/php.ini file recursive, edit (or create the file if it doesn’t exist) your public_html/.ht access file and add the following code:

suPHP_ConfigPath /home/username/public_html

This line you entered is specifying the directory where the php.ini is located that you want to make recursive.

Be sure to replace your username with your cPanel username. This change is immediate, so you should see the update right away.

[/su_code]

for detail readers : How to Make php.ini file recursive in cPanel shared hosting

For WordPress

To resolve the “fatal error allowed memory size of bytes exhausted” in WordPress, you can try the following steps:

  1. Increase the memory limit in the wp-config.php file by adding this line of code: define(‘WP_MEMORY_LIMIT’, ‘256M’);

  2. Deactivate and delete any unnecessary plugins. Some plugins can consume a lot of memory and cause this error.

  3. Optimize your images before uploading them to your website. Large images can also consume a lot of memory.

  4. Enable caching on your website to reduce the amount of memory needed to generate each page.

  5. If you are Netspace customer for WordPress Hosting, Do contact us and we will be happy to help you on the same. we will increase the memory limit for your account, if none of the above steps worked

It’s worth noting that these steps should be taken one by one, and not all at the same time, so you can see what is working and what is not.

For laravel

To resolve the “fatal error allowed memory size of bytes exhausted” in a Laravel application, you can try the following steps:

  1. Increase the memory limit in the .env file by adding this line of code: PHP_MEMORY_LIMIT=256M

    The .env file in a Laravel application is typically located in the root directory of the application. You can find it alongside other important files like the index.php, composer.json, and README.md files.

    This file contains environment-specific configuration settings for your application, such as the database connection details, app key, and other settings. You can edit this file to change the values of various configuration options, including the memory_limit.

    It’s worth noting that in Laravel 8 and above, the .env file is no longer mandatory and you can use the .env.example file as a reference to create your own .env file.

    It’s also important to keep in mind that you should never commit the .env file to your version control system, as it contains sensitive information.

  2. Increase the memory limit in the php.ini file by editing the memory_limit setting. The location of the php.ini file may vary depending on your server configuration.

  3. Optimize your code and avoid memory leaks, for example, closing database connections and other resources when not needed.

  4. Use a task scheduler like “Task scheduler” or “Cron job” instead of running expensive tasks in real-time

  5. Deactivate and delete any unnecessary plugins and packages in your Laravel application

  6. If your laravel is hosted under our web hosting services, please feel free to contact us and we will be happy to help you.

  7. check the error log in the server and check if you have any memory leakages, if so, try to optimize your code and also make sure your application is running on the latest version of Laravel.

Drupal

To resolve the “fatal error allowed memory size of bytes exhausted” in a Drupal application, you can try the following steps:

  1. Increase the memory limit in the settings.php file by adding this line of code: ini_set(‘memory_limit’, ‘256M’);

    The location of the settings.php file in a Drupal application can vary depending on your installation.

    For Drupal 7 and earlier, the settings.php file is typically located in the sites/default folder, and it is used to define the configuration settings for your Drupal site.

    For Drupal 8 and later, the settings.php file is located inside the sites folder. Inside the folder, you have multiple folders, one for each website or sub-site.

    The path would be sites/<your_site>/settings.php where <your_site> is the folder of your specific website.

    It’s also important to keep in mind that it’s a good practice to create a copy of the default settings.php file and name it settings.local.php or settings.dev.php and make changes to that file, that way you can make sure that your custom configuration is not overwritten when updating Drupal.

  2. Disable and remove any unnecessary modules. Some modules can consume a lot of memory and cause this error.

  3. Optimize your images before uploading them to your website. Large images can also consume a lot of memory.

  4. Enable caching on your website to reduce the amount of memory needed to generate each page.

  5. Check your website’s error logs to see if there are any memory leakages, if so, try to optimize your code.

  6. if you have access to the server, you can also try to increase the memory limit in the server’s php.ini file.

It’s also important to keep in mind that you should keep your Drupal application up to date, as new versions may include bug fixes and performance improvements.

Conclusion

In conclusion, PHP-based apps like WordPress, Laravel, and Drupal may experience the “fatal error allowable memory size of bytes exhausted” fault frequently. This error happens when a PHP script attempts to use more RAM than what the server’s setup permits. You can attempt to fix this problem by increasing the value of the memory limit setting in the settings.php or.env files, which are application-specific configuration files, on your server. Additionally, you can try to optimise your code to utilise less memory by disabling unused modules and packages and removing unused packages.


It’s crucial to follow these instructions step-by-step and to inspect the server’s error log to determine the precise source of the error.

Facebook
Twitter
LinkedIn
Digg
Picture of Shashi kant Pandidhar

Shashi kant Pandidhar

I’ve been helping businesses to be online for over 15 years. Today my team and I, focus on helping real businesses to overcome real-life challenges and analyse data in a way that can help businesses grow in the right direction of this digital age.

Leave a Comment

Get the latest news and deals

Sign up for email updates covering blogs, offers, and lots more.

Current Deals at Netspace

Subscribe: Trusted By 1M+ Readers

Get the weekly Tech Update straight to your inbox.

//
Our customer sales team is here to answer your questions. Ask us anything!
👋 Hi, how can I help?

Free .Online Domain

Every Active Netspace (India) Customer is eligible for a free 1-year non-premium .ONLINE / per account
The campaign runs until December 31 of 2024!

100% off

on your first Year