wordpress, php,

Resolving WordPress, PHP's "Fatal error: Allowed memory size of X bytes exhausted"

Feb 08, 2023 · 2 mins read · Post a comment

If I got a dollar for every temporary, quick fix found on the Internet for any type of error, I’ll be so rich. Before else, WordPress and LAMP stacks makes the majority of websites out there, it’s annoying. While I was trying to “fix” a 1GB of memory VPS instance, I’ve noticed the following error in the logs: Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 45 bytes). This could mean at least two things. Either there is not enough memory for the PHP app, in this case WordPress, or second, there is a code memory leak.

Prerequisites

  • WordPress LAMP stack

Solution

the dirty fix

Just increase the memory limit, or even the system, VM’s memory as well lol.

Step 1. Find and update the memory limit parameter value.

Step 2.1. Regarding WordPress, open wp-config.php file and find or add (if it’s non-existing one) the following line:

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

For my part, the WP_MEMORY_LIMIT was set to 256MB initially, so I double it. It’s important to note that by default WP_MEMORY_LIMIT value is 40MB.

Step 2.2 On the other hand, if you are dealing with a PHP application, that’s not WordPress, first find the php.ini file.

php --ini

Step 2.2.1. Next, update the memory_limit parameter. For instance:

ini_set('memory_limit', '512M');

Whatever you do, just do not set the value to -1, as it means to use “unlimited” memory. All your system memory will be consumed, gone, 100%.

However, increasing the memory in terms of megabytes, not a big deal in today’s age. At least it doesn’t surprise me these days. Almost no one bats an eye about memory optimizations, garbage collection, and so forth. Nonetheless, you can always vertically scale the server instance. But, if you can’t “satisfy” the application memory requirements in terms of gigabytes, unless it’s a memory intensive app, then you probably have some code leaking issues, which leads to the second solution.

a better solution

There is no universal solution, but as a good starting point, try to disable all WordPress plugin, and reactivate them one by one.

Conclusion

If you have any other great solutions on this topic, or even issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.