- wp-config (.php) file
- .htaccess file
- php.ini file
When the allowed memory size of an allocated amount of bytes is exhausted it means the php script responsible for running a process or function has been exceeded. This can occur when poorly optimized scripts or too many resources (like plugins) attempt to allocate too much or all of the memory available on a server.
If you have a WordPress site of your own, or you are familiar with working with them on a regular basis, chances are you’ve seen an error message like the one below:
Fatal error: Allowed memory size of … bytes exhausted (tried to allocate … bytes) in /… on line …
Memory limits are ultimately defined by the host, but WordPress memory can be different from the server memory, and can be overridden by WordPress (if the host allows it).
WordPress will autimatically increase the memory limit of single sites to 40MB and multi-sites to 64MB, which may not be high enough for resource intensive and high-traffic sites.
There are typically X3 methods worth exploring if you need to increase the memory limit to resolve a memory error. You will need server or file manager (FTP) access to attempt the following.
1. wp-config (.php) file
wp-config (.php) file to insert the following snippet just before the “That’s all, stop editing! Happy blogging.” line.
WP_MEMORY_LIMIT increases the default memory for front-end and back-end operations.
WP_MEMORY_LIMIT option allows you to specify the maximum amount of memory that can be consumed by PHP. This setting may be necessary in the event you receive a message such as “Allowed memory size of xxxxxx bytes exhausted” [Wordpress Codex]
If the problem occurs in the backend only, you should try increasing the max memory limit using the following WordPress contant
define( ‘WP_MAX_MEMORY_LIMIT’, ‘256M’ );
This way you don’t allocate too much memory to frontend operations that could end up affecting performance.
Administration tasks require much more memory than usual operation. When in the administration area, the memory can be increased or decreased from the
WP_MEMORY_LIMIT by defining
WP_MAX_MEMORY_LIMIT. [Wordpress Codex]
This means that
WP_MAX_MEMORY_LIMIT will always override the limit set by
WP_MEMORY_LIMIT (whether it’s higher or lower) for admin pages (back-end processes).
This setting (
WP_MEMORY_LIMIT) increases PHP Memory only for WordPress, not other applications. By default, WordPress will attempt to increase memory allocated to PHP to 40MB for single site and 64MB for multisite, so the setting in
wp-config (.php) should reflect something higher than 40MB or 64MB depending on your setup. [Wordpress Codex]
2. .htaccess file
If the site is hosted on an Apache server (not Nginx or IIS servers), and configuration dotfiles are not hidden, you should have access to the
.htaccess file in the root folder.
.htaccess file is loaded every time a document is requested. You can also add an
.htaccess file to any directory or sub-directory that serves documents to specify rules where it is required.
.htaccess file to insert the following snippet
php_value memory_limit 256M
Warning: always back-up the .htaccess file before updating it
3. php.ini file
php.ini file is the default php configuration file. You typically find it in the server root folder, or any sub-directory folder (e.g /wp-admin) with specific configurations needed. You may not have access to this file but you should be able to create and edit your own to overwrite any defaults set.
php.ini file to insert the following snippet
memory_limit = 256M
Contact your hosting providers if all else fails
If none of the above methods resolve the memory error contact your hosting providers and request an increase in the default php memory limit.