How to Increase the Maximum Upload and PHP Memory Limit
Dealing with Fatal Errors in WordPress is a rite of passage. It happens to everyone eventually.
If you have a multimedia-rich site, then the standard configuration for WordPress will not meet your needs and at some point, you will experience one of the following errors:
“Fatal error: Allowed memory size of XXXX bytes exhausted” and “filename.jpg exceeds the maximum upload size for this site.”
The easiest way to fix these issues is to reach out to your host to help you reconfigure WordPress. If you want to do this yourself and you’re comfortable editing your site files, then read on.
We’re going to cover several ways to modify your WordPress files with a few lines of code so you can increase the maximum PHP memory limit and the maximum upload file size.
What is the PHP Memory Limit in WordPress?
PHP is the server-side language that generates the HTML pages that create your site. PHP is a powerful, dynamic language that can do things like perform calculations, process WordPress queries, and more, but it needs memory to carry out these operations.
The default memory limit for WordPress is 32MB, but it’s common to have to increase it. WooCommerce’s recommended PHP memory limit for WordPress is 64MB, for example.
When WordPress reaches the default memory limit, it will attempt to increase the memory to 40MB for a single site install and 64MB for multisite. If that isn’t enough, then you will see the fatal error message.
A PHP memory limit of 128MB should be more than enough for most sites unless you have a plugin that needs more. If you want to see how much memory different plugins use, install the Server IP & Memory Usage Display plugin.
Once you activate the Server IP and Memory Usage Display plugin, you can deactivate the plugins and see how they affect memory usage. Quality plugins should use memory efficiently to avoid overloading your server.
Why does WordPress need more memory to begin with?
In one way, increasing the WordPress memory limit is a quick adjustment similar to increasing the max upload size in the WordPress wp-config.php file; however, you need to be careful because increasing the memory limit can sometimes make inefficiencies in WordPress harder to detect.
Before increasing the Memory Limit in WordPress, I want to encourage you to first try to uncover what is sucking up so much memory. Oftentimes, throwing more resources at a problem may cost a lot more in the long run, especially if you have to upgrade hosting plans. Inefficiencies in WordPress also manifest as a slower site and poor user experience, so getting to the root of the problem, can fix multiple downstream issues you may be having.
One component of WordPress that is prone to issues if overlooked, is the version of PHP your hosting server is using. Only 4.4% of WordPress sites are running the latest version of PHP, with 64% running a version of PHP that is no longer receiving active updates.
Not only does this compromise security, but updating to the latest version of PHP on your hosting server will make WordPress more efficient and negate the need to increase the memory limit in WordPress.
What is the Maximum Upload Limit in WordPress?
The maximum upload limit in WordPress refers to the maximum file size for your uploads that WordPress will allow. You can see what the maximum upload limit is in WordPress in the media library upload screen.
This is a server-side setting that hosts use to reduce the number of resources needed to serve your site. It’s a way to keep you from uploading huge files and images.
While this may benefit your host, it also helps your site performance as well. Uploads in the form of huge images, for instance, perform poorly on your site because they take longer to download and serve.
So just like with the memory limit, before you throw more resources at the problem and increase the upload limit, see if there’s something you can do to reduce the file size first.
If your images are too large for their container or if you haven’t compressed your images, then you’re better off correcting those issues because they address the cause of the issue, which is not optimizing your assets correctly. Check out our guide to optimizing images for more.
How to Increase PHP Memory Limit and Maximum Upload Limit in WordPress
In the event that you still need to increase the memory limit and uploading limit in WordPress, there are three methods you can use.
As with any major change, you should always create a new backup of your site files and database so you can restore your site if you make a mistake.
While this is a one-step tutorial, this isn’t something that you should feel the need to tackle alone because it appears to be simple.
Definitely employ the help of your web host. They can not only make these changes but they will also help if something goes wrong. They can also help you determine if this fix is necessary or if something else may be a better fix.
Also, some hosts may not even allow you to access these files to make changes so you’ll have to reach out to your host for help.
If you don’t want to deal with any of this alone and want a reliable host with amazing 24/7 support, try WPMU DEV hosting, 100% risk-free.
To access the files below, you’re going to have to connect to your site via SFTP. SFTP is like FTP but more secure. See how to use SFTP or FTP to manage files in WordPress for a detailed tutorial. You can not edit these files from within WordPress like other theme files.
1. Edit your wp-config.php file
Wp-config.php is one of the most important WordPress files because it contains your base configuration details. You’ll find it in the root of your WordPress file directory.
To edit the memory limit and upload limit, look for this line:
define('WP_MEMORY_LIMIT', '32M');
Modify the second parameter by increasing it. As I mentioned a PHP memory limit of 128M should be more than enough, and for many hosts (including ours) this is often the maximum file upload size.
define('WP_MEMORY_LIMIT', '256M');
Save the file and you’re done.
If you’re trying to upload files that are larger than this memory limit you will continue getting the fatal error. Reach out to your host for help if this is the case and they will advise on the best solution for your circumstances.
2. Edit your PHP.ini file
If modifying your wp-config.php file doesn’t address the problem, you’ll have to address the issue within your server settings instead of within WordPress.
If you’re using shared hosting, you will not be able to access your PHP.ini file, so see the next option instead. If you do have access to PHP.ini, you’ll most likely find it in the root folder, but the location of the file will vary by host.
To increase the PHP memory limit and upload limit, change these lines in PHP.ini
memory_limit = 512M
upload_max_filesize = 512M
post_max_size = 1024M
file_uploads = On
max_execution_time = 600
Changing the value of max_execution_time
will limit the amount of time for a PHP script to run. If the PHP script exceeds the set value (seconds), it will stop the script and report an error.
In many cases, the values you enter should get larger as you go down the list from lines one to three. The upload_max_filesize
should be the smallest while memory_limit
should be the largest. The median should be post_max_size
.
Before checking to see if the error is gone, clear your browser’s cache.
3. Edit your .htaccess file
If you don’t have access to PHP.ini, then your last resort is to modify your .htaccess file. Your .htaccess file starts with a dot because it is a hidden file. If you don’t see it in your root folder, check to make sure that your SFTP file manager isn’t keeping those files hidden from view.
To increase the PHP memory, you’ll add the following to your .htaccess file:
php_value memory_limit 128M
php_value upload_max_filesize 12M
php_value post_max_size 13M
If the PHP value memory limit has already been set, then increase it.
4. Adjusting the Maximum Upload Limit Using Branda
You can use the Images Utility in Branda to override and restrict the upload size for different user roles without modifying any code.
Note: With this method, you cannot increase the upload_max_filesize
value that is already set in wp-config
, .htaccess
or php.ini
. You can only update the upload limit for different user roles to a lesser value.
First, go to Utilities > Images to activate the module.
Then you’ll see a setting for Override Upload Limit. Flip the switch to activate.
Here, you’ll be able to set the limit on upload size for different roles. Don’t forget to save your changes.
If you’re still having a problem
Configuring your server and dealing with fatal errors in WordPress can be a nerve-wracking experience. The process you need to follow is highly dependent on the hosting company you’re using, which is why having a host you can count on to help you is so important. They can help you find and modify the settings you need to adjust.
Unfortunately, if you’re using cheap shared hosting, you may find that you’re not able to make all the changes you need to make to operate WordPress the way you want. In these cases, it may be time to upgrade your hosting setup to something more robust. Not only will you get more flexibility when it comes to configuring WordPress, but you’ll also see an improvement in other performance metrics if you use a quality host.