PHP comes with default settings that may need to be changed according to the scope and size of the website project. One of these is the memory limit. In this article, we shall explore how we can increase the memory limit for the better working of a website, that obviously needs more memory!
Your site may need extra memory to run a new process. When processing a website, PHP allocates a default amount of memory for it. But when this need becomes greater you’ll have to manually increase the memory limit.
You might have received the following error on your website:
Fatal error: Allowed memory size of 94371840 bytes exhausted (tried to allocate 5072 bytes).
This is a really common error. Luckily, we have an easy fix for this. Read on to know more.
P.S. If you need professional assistance with this, our expert team of WordPress ninjas can help you out!
What is this error?
Let’s understand what this error really is shall we? For those who don’t know, WordPress is programmed in PHP. Now PHP is a server-side programming language. Your website needs a WordPress hosting server to run.
These web servers are computers that need memory to run different applications. A specific amount of memory is allocated to different applications, including PHP.
This error is usually seen when your code requires more memory than the already allocated default memory.
The other ways this memory problem can manifest itself are issues like the white screen of death and the 500 internal server error.
How to increase PHP Memory limit in WordPress?
First, you’ll need to decide your memory limit. You’ll need to use an FTP client like FileZilla for this. Click here to download and start using FileZilla.
Install and open it. Here’s how you can start using FileZilla. Go to File > Site manager and give your site a name. Then under the General tab, enter details as shown:
Host – Your domain example: vividreal.com
Port – you can leave this blank
Protocol – FTP – File Transfer Protocol
Encryption – Only use plain FTP (insecure)
Logon Type – Normal
Enter the user and password details of your WordPress site. If your website uses cPanel, enter the login details of cPanel.
Now go to Transfer Settings, and check the box that says Limit Number of Simultaneous Connections. In the Maximum Number of Connections, enter 8. Finally, click on connect to access your website’s files.
Finding your WordPress memory limit.
After the above steps, you need to find a file named default-constants.php in the root folder of your website (public_html).
Open the wp-includes file, and find the default-constants.php file. Save it to your computer and open it using notepad. The website memory limit will be visible in a few lines of code.
WP_MAX_MEMORY_LIMIT gives you an indication of how much memory you’re allowed to use on the administrative side.
How to determine the amount of memory you need?
The amount of memory your WordPress website needs depends on the number of plugins you have, and even on all the media your website contains.
You’ll need to decide on a memory limit which is higher than what you found in your default-constants.php in the step above. You may need to find out the amount of memory you need through trial and error. Increase your memory limit manually, bit by bit until the issues of your website have been resolved. You shouldn’t increase it to more than what your site needs. Raising this number too high can make your server crash, so be careful!
Okay, let’s start talking about the ways you can increase your memory limit. Before you start tweaking, clear your browser’s cookies and cache so that they do not affect how your website appears.
In your wp-admin folder, find the php.ini or php5.ini file, download it to your computer. Find the below code and edit it as such:
Upload it back to the wp-admin folder, overwrite the original file, refresh the FTP client, and reload your page to see if the issue has been solved. If it hasn’t, try increasing the value from 512M to another value. You can also try renaming the file from php.ini to php5.ini and vice versa.
If this doesn’t work, revert all changes made before trying out the following steps.
You’ll need to find the .htaccess file, located in your root directory. There’s a chance that this file may be hidden, so if you’re using FileZilla, go to Server > Force showing hidden files.
Once you find the .htaccess file, download it, make a copy and in the copy, add the following code, or edit it if already exists:
php_value memory_limit 512M
Save the file, upload it back to your root directory, refresh the FTP client and refresh your website to see if the issue has been solved. If not, try increasing the value. If this doesn’t solve the issue, delete the copy and upload the original .htaccess file back to your root directory before you try any other step.
You need to find and edit the wp-config.php. You can find this in the root folder of your website.
Once you’ve found the file, simply copy-paste the code in the wp-config.php file. Paste it just before “That’s all, stop editing! Happy blogging.”
Here’s the code:
define( ‘WP_MEMORY_LIMIT’, ’64M’ );
This tiny little code tells WordPress to increase the PHP memory limit to 64MB. Increase this value if needed.
Once done, save your changes and upload the wp-config.php file to the server, and refresh the website. The error message should have disappeared by now.
Now in the off chance that this does not work, it probably means that your web hosting server does not simply allow WordPress to increase PHP memory limit. The only workaround to this is to contact your hosting provider and request them to increase the PHP memory limit manually.
So there you have it, three simple ways you can increase your PHP memory limit for your WordPress website. Remember to create a backup of your website before you go tweaking! It’s always better to get professional help if you do not know what you’re doing. If things are getting confusing for you, just give us a try; we’d love to help!