Article directory
WordpressFatal error: Out of memory? Teach you how to fix the WordPress memory_limit problem in 5 minutes
1. Problem Overview
currently using Wordpress If you encounter such an error:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 10220888 bytes)
this means PHP Out of Memory, causing the system to not work properly. Your backend page cannot be opened and the dashboard function is also stuck.
This error is particularly common in high-volume or enabledWordPress pluginToo many websites.
Even if you increase the memory 512M,even 3024M, the question still remains, what is stuck?
We will analyze the possible reasons step by step and teach you how to solve this problem once and for all.

2. Why is raising memory_limit still ineffective?
You have already memory_limit From the default 256M promoted to 512M 和 3024M, but the problem remains. This means:
- PHP settings not taking effect: Some server environments may ignore your manual changes
php.ini. - Plugins or themes taking up too much resources: Some plugins or custom code consumes excessive memory.
- Server Configuration Limitations: The server may have set a hard limit on the memory allocation for PHP scripts, making the setting invalid even if it is exceeded.
To solve this situation, you need to thoroughly check the configuration of the server and WordPress.
3. Step-by-step solution
1. Modify the php.ini file
First find your php.ini file, which is usually located in /etc/php/ Or /usr/local/php/ under the path.
Search memory_limit, make sure it is set to:
memory_limit = 512M
Then restart your Web server :
- Apache :
sudo service apache2 restart - Nginx :
sudo service nginx restart
prompt: Some shared hosts do not have access to php.ini, in which case you can skip to the next method.
2. Override PHP memory limit in wp-config.php
Even if the server's memory is configured correctly, WordPress may sometimes run out of memory due to its own settings.
So, you can wp-config.php Manually set the memory limit in the file:
define( 'WP_MEMORY_LIMIT', '512M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
Put this code in wp-config.php Documentary Top, to ensure that it takes effect when loaded.
- WP_MEMORY_LIMIT: Front-end memory limit, controls resource usage when users access pages.
- WP_MAX_MEMORY_LIMIT: The background memory limit ensures that management operations do not fail due to insufficient memory.
3. Check memory usage of plugins and themes
some Resource-intensive plugins May cause memory exhaustion, such as cache plugins,SEOplugin orE-commercePlugins (like WooCommerce).
Solution :
- Close all plugins and enable them one by one to troubleshoot.
- Switch to a default theme (such as Twenty Twenty-Three) to see if the problem is solved.
- 使用 Query Monitor plugin to view components with high memory consumption.
4. Use .htaccess or user-defined PHP settings
If you are using shared hosting, you can modify .htaccess File to increase PHP memory:
php_value memory_limit 512M
After saving, refresh your dashboard page to check if the problem is resolved.
5. Contact the server provider
In some cases, the server enforces limits on PHP's memory usage.
Even if you change the memory limit, the server will not take effect.
At this time, you need to contact your hosting provider, ask them to help you increase the memory quota.
4. Final solution: disable unnecessary functions and optimize code
Even if you successfully increase the memory limit, you cannot ignore the website Performance optimizationOver-reliance on plugins or using resource-intensive themes can cause frequent low memory usage. Therefore:
- delete Unnecessary plugins and redundant code.
- Use efficient caching plugins (such as WP Rocket Or W3 Total Cache).
- Regularly optimize the database and clean up junk data.
5. Summary: Efficient steps to solve memory_limit
- Make sure the changes to php.ini take effect:set up
memory_limit512M or higher. - Define the memory limit in wp-config.php: Make sure WordPress is using enough memory.
- Troubleshoot plugin and theme issues: Disable plugins that consume a lot of resources.
- Contact the server provider if necessary: Make sure the server is not enforcing a memory limit on your PHP.
- Optimizing site performance: Reduce unnecessary plug-ins, optimize the database, and improve overall operating efficiency.
Optimization is a long-term solution, memory is just the foundation
By following the steps in this article, you can not only solve this annoying fatal error, and also learned how to troubleshoot memory problems.
However, simply increasing memory usage is not a fundamental solution to website problems.
Reasonable code optimization, cleaning up useless plug-ins is the key to keeping the website running stably in the long term.
I hope you learned something from this article and put these tips into practice right away!
Is there anything more satisfying than solving a tough problem? 💪
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ )’s shared article “Solving WordPress fatal error Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 10220888 bytes)” may be helpful to you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-32129.html
To unlock more hidden tricks🔑, welcome to join our Telegram channel!
If you like it, please share and like it! Your sharing and likes are our continuous motivation!