How to Increase the Maximum Upload and PHP Memory Limit (2022)

Dealing with Fatal Errors in WordPress is a right 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 xxxxxx 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 plugins and see how it affects 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 the latest version of PHP 7.3, can handle as much as 3x as many requests per second as PHP 5.6. So 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 also where the max upload size error message shows up

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

Edit your wp-config.php file
Edit your PHP.ini file
Edit your .htaccess file
Increasing the Maximum Upload Limit Using Branda

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 webhost. 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.

These files should be in the root folder, but your host may also put them somewhere else

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.

define(‘WP_MEMORY_LIMIT’, ‘128M’);

Save the file and you’re done. You may need to increase it again if you’re still getting the fatal error, but don’t go overboard or you may crash your server. All the more reason to reach out to your host for help.

If this line is missing and you need to set the PHP memory limit, enter it right above the “Happy Blogging” line

If you’re running into a memory limit fatal error in the admin area of WordPress, then you’ll need to modify a different line in your wp-config.php file.

To increase the WP memory limit for the administration area look for this line and increase it:

define( ‘WP_MAX_MEMORY_LIMIT’, ‘256M’ );

Admin tasks require more memory, so you’ll need to set it much higher. Double the number you set for WP_Memory_Limit.

2. Edit your PHP.ini file

In the event that 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 = 256M
upload_max_filesize = 12M
post_max_size = 13M
file_uploads = On
max_execution_time = 180

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 256M
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. Increasing the Maximum Upload Limit Using Branda

For an easy way to update the upload limit without modifying any code, you can use the Image Utility in Branda. First, go to Utilities > Images to activate the module.

Activate Branda Utilities Images

Then you’ll see a setting for Override Upload Limit. Flip the switch to activate.

Go to Image Filesize Limit

Then you’ll be able to set the limit on upload size for different roles. Don’t forget to save your changes.

Only want to allow Admins to upload big files? You can specify file size by role.

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 in order to operate WordPress the way you want. In these cases, it may be time to upgrade your hosting setup to something that is more robust. Not only will you get more flexibility when it comes to configuring WordPress, but you’ll also see an improvement to other performance metrics if you use a quality host.

If you’re ready to upgrade, why not try WPMU DEV hosting? Freelancer and Agency members get free hosting credits, plus access to our entire range of performance and profit-enhancing plugins, client billing, and more. Sign up for a free trial to get access to blazing-fast WPMU DEV hosting risk-free.

Щелкните ниже, чтобы поставить оценку!
Всего: 0 В среднем: 0

Написать комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *