“Allowed memory size of 33554432 bytes exhausted (tried to allocate 91 bytes)”. This error message is one of the first WordPress beginners stumble upon, when trying to carry out their first customizations, such as uploading a premium theme, backing up their site or even publishing a post. It can also be pretty scary, especially because it seems that the error comes out of the blue and is thus difficult to understand.
No worries, there are several ways to increase the PHP memory limit for WordPress and they are all easy and painless.
What Is PHP Memory Limit?
PHP memory limit is a setting defining the max memory size a PHP script can use. Explained in layman terms, this means that a process, such as installing a plugin or publishing a post, cannot be executed as long as it requires more than the set limit.
This limitation is usually set on a server level and affects all users on the server. Sometimes web hosts set the PHP memory size limit as low as 8MB, which gives problems even with simple actions as publishing a post.
By default, WordPress will try to increase the allocated PHP memory limit to 40MB for single site and 64 MB for multisite. However, many premium plugins and themes require a minimum of 128 MB in order to be installed or function properly. For comparison, WPBloggingNerd has its PHP memory size limit set at 512MB.
OBS! Be aware that while increasing the PHP memory limit can enable the execution of certain processes, it can also slow down your site or crash it when set too high! The role of this limitation is to protect the server from abuse.
Fix WordPress PHP Memory Size Limit with .htaccess
.htaccess is an invisible file in your WordPress directory on the server. You can find it by logging into your File Manager on the server or by using your preferred FTP client to access your WordPress core files. Navigate to Public_html directory and choose .htaccess.
If using File Manager, you can either download the file or edit it directly on the server by clicking on Edit in the top menu. No matter which option you choose, it’s crucial that you save a copy of the original before changing anything, in case something goes wrong!
Open the file and write the following line (don’t copy-paste!) below its current content:
php_value memory_limit 512M
M at the end of the line stays for MB. You can choose yourself the value for the PHP memory limit, just remember to not allow unlimited – or too large – memory usage!
Once you’ve added this piece of code to .htaccess, save the file without renaming it. If you downloaded it to edit it locally, you have to upload it back to the same directory on the server. You have to choose to overwrite the existing file. If you edited the file without downloading, saving it is enough to make it work.
Fix WordPress PHP Memory Size Limit with wp-config.php
wp-config.php is a file that gets created during the installation of WordPress. It’s found in the same directory, Public_html, as .htaccess on the server (see the picture above for reference). You can either edit it directly on the server, when using File manager, or download it and edit it locally (use File manager or FTP client).
wp-config.php is quite an intimidating file, as it contains a lot of data, crucial for your website, such as information about the WordPress database and secret keys, along with a lot of writing. The fact is that a lot can go wrong if you change something in this file that shouldn’t be changed. Therefore, please do backup the file before tweaking it!
To increase the PHP memory size limit, find the line in the document, just after WP_DEBUG and before “Happy blogging!” (see pic below).
On the marked line, write the following piece of code:
Save the file without renaming it. If you downloaded it before editing, upload it to the same directory and choose to overwrite the existing file on the server. All done.
Fix PHP Memory Size Limit With A Plugin
The edits, described above, are way too simple to require the use of a plugin. However, it might be that you for some reason don’t feel comfortable touching core files. No worries, you can use a plugin to increase the memory limit in WordPress. Use, for example, Change Memory Limit, a simple plugin with good reviews (not so many though) that will do the file edits for you. It hasn’t been updated in the last 5 years so far but, given its simplicity, regular updates aren’t a must.
Even though such plugins tend to be pretty simple scripts, be aware that you risk plugin incompatibility every time you install or update a plugin! I do recommend to try and edit the .htaccess or wp-config.php yourself instead.
Additional Considerations And Debugging
Whenever performing a change to core files, it’s very important to check, whether your site functions properly after the operation is carried out. This applies also to increasing the PHP memory size limit. Even though it is a fairly simple task, a lot of things can go wrong, if you, for example, accidentally delete or change something.
This is also why you should always backup the files you edit. Sometimes, after, for example, writing improper code or making an accidental error while editing your core files, you might get locked out of your site. No worries though. As long as you backed up your original files, all you need to do is upload the original and overwrite the existing file on the server. Then try to apply the changes again, this time properly.
The solutions offered here will help you increase the PHP memory limit for WordPress in almost all cases. However, some web hosts might disallow you to perform such changes. If that is the case, you won’t be able to solve the issue yourself. You have to contact your web host and ask them to increase the PHP memory size limit.