Fatal error: Allowed memory size exhausted on WordPress
When you encounter a Fatal error: Allowed memory size of 67108864 bytes exhausted, it means PHP has hit its hard limit for RAM usage before your script could finish executing. The error message explicitly states that the process tried to allocate an additional 122,880 bytes (roughly 120 KB) but was denied because the total allowed memory is currently set to 64 MB (67108864 bytes).
This specific scenario often happens on shared hosting environments like 000webhost, where you might not have direct access to a php.ini file or server-level configuration tools. In these cases, the standard practice is to define the memory limit directly within your WordPress installation's wp-config.php file. However, there is a critical technical distinction between increasing the PHP memory limit and increasing WordPress's internal cache memory limit, which often leads to confusion.
The Correct Constant: WP_MEMORY_LIMIT vs. WP_MAX_MEMORY_LIMIT
The code snippet you found referencing define('WP_MEMORY_LIMIT', ...) targets a specific internal WordPress variable used for caching mechanisms (like the object cache). While increasing this constant is safe, it does not solve the fatal error you are seeing if PHP itself has been configured to stop execution at 64 MB.
The error message you are facing (Allowed memory size... exhausted) is a PHP-level restriction, not a WordPress-level one. To resolve this on shared hosting where you cannot edit php.ini, you must use the constant that actually overrides PHP's default memory allocation within the context of your application.
You need to add the following line to your wp-config.php file:
define( 'WP_MEMORY_LIMIT', 256 ); // Set to megabytes, e.g., 128 or 256
Where to place it:
The wp-config.php file typically resides in the root directory of your WordPress installation (the same folder where wp-load.php, wp-login.php, and .htaccess are located). You should insert this definition before the line that says:
/* That's all, stop editing! Happy blogging. */
The standard structure of the file usually looks like this:
- Database credentials (
DB_NAME,DB_USER, etc.) - MySQL data settings (if custom)
- Authentication Unique Keys and Salts
- Your new line here
- WordPress Debugging mode (
WP_DEBUG) - The "Stop editing" comment
Why the Source Location Changes
You mentioned that the error source ("in...") always changes. This is expected behavior for memory exhaustion errors. PHP does not fail immediately upon hitting the limit; it continues allocating memory until it absolutely cannot find space for a specific operation. That operation could be processing a large image, running a complex query in wp-config validation, or executing a plugin hook. Because the allocation attempt happens at different stages of execution depending on what is currently being processed, the file path and line number reported in the stack trace will vary from one incident to the next.
Trade-offs and Limitations
While adding the definition above helps, be aware of the environment's constraints:
- Shared Hosting Limits: If your host (000webhost) has strictly capped your PHP memory at 64 MB in their
php.inior via.htaccess, defining the constant inwp-config.phpmight not work if the server rejects the configuration directive entirely. In such cases, you may need to contact support to request a higher PHP memory limit allocation. - Internal Cache vs. General Memory: The constant
WP_MEMORY_LIMITspecifically affects internal caching (used by plugins like Object Cache). If your issue is caused by a plugin consuming too much general RAM, you might also need to definedefine( 'WP_MAX_MEMORY_LIMIT', 512 );immediately following the previous line to ensure WordPress itself isn't throttled down during heavy processing.
Final Recommendation
If you are new to programming and managing domains, stick to the simplest effective fix first:
- Open
wp-config.php. - Add
define( 'WP_MEMORY_LIMIT', 256 );before the "Stop editing" line. - If that doesn't resolve it, add
define( 'WP_MAX_MEMORY_LIMIT', 512 );right after.
If these changes do not stop the fatal error, the limitation is likely enforced at the server level by your host provider, and you will need to contact their support team to adjust the server-side PHP memory limits rather than trying to override them via code.