Increase the WordPress Maximum Upload File Size

The Media uploader Problem

Sometimes when we are trying to upload an image, audio or a pdf and if it is a big size suddenly we see “exceeds the maximum upload size for this site.” It’s important to understand that this is usually not a WordPress issue. In most cases, the WordPress maximum upload file size is a server-level setting which also means that you can’t resolve it from within WordPress.

 

This limit exists for security and efficiency’s sake. It prevents users from flooding your site with huge video uploads and grinding your servers to a halt. I think that’s fair enough, but nowadays a default upload of 2MB (an amount many servers default to) just doesn’t cut it, let’s see how we can go about increasing it.

Increasing The WordPress Maximum Upload File Size

There are three basic ways you can go about solving this issue. I’ll start with the two easiest ones, then move on to changing the server settings yourself – there are a number of options here as well.

Increase Upload Size Limit In a Multisite Install

If you are running a multisite installation you may be able to control the upload limit for your sites in Settings->Network Settings, near the bottom. Note that this can not circumvent the server settings. If the server is set to a limit of 5MB and you set 10,000 Kb (10MB) in the network settings it will not work.

If, however, the server is set to 20MB and your network settings are set to 1,500 Kb you will be able to resolve the issue by increasing the setting up to the 20,000 Kb limit.

Ask Your Host For Help

Many hosting companies have chat support which can help you out in these situations. Increasing an upload limit is a trivial task for a tech support person, they should be able to do it within a minute.

Modify Server Settings

There are a bunch of server settings that affect how uploads are handled. Regretfully, many tutorials get this wrong because they change more settings than necessary. According to the PHP Documentation, the three directives that matter are:

  • post_max_size
  • upload_max_filesize
  • memory_limit

The documentation also gives us pretty clear guidelines on how they should be set up:

[post_max_size] sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size.

 

We’ll need to set these three up to accommodate for our file sizes. If the largest file will be about 10Mb, I would recommend settings upload_max_filesize to 12M (12 Megabytes), post_max_size to 13M and memory_limit to 15M. Uploads can contain a fair bit of text information in addition to the file itself so giving everything some breathing space is a good idea.

Now that we know what to modify, we just need to know how. There are three things you could try. Some of these may not work for you, depending on your server setup.

Create Or Modify php.ini Files

By default, php.ini files are the ones that govern how your server is set up. Due to restrictions in servers you may not be able to use php.ini files, which is why the .htaccess method works more consistently, we’ll take a look at that next.

Go to your site’s root directory and open or create a php.ini file. If the file was already there, search for the three settings and modify them if necessary. If you just created the file, or the settings are nowhere to be found you can paste the code below.

upload_max_filesize = 12M
post_max_size = 13M
memory_limit = 15M

With a PHP Settings plugin

This is most easy and effective way to update the WordPress Maximum Upload File Size. after installing the plugins just add the code to the Editor like below image

WordPress Maximum Upload File Size

You can also set and view the current status of php.ini of your hosting. This is the most effecting way to increase WordPress Maximum Upload File Size. Want to try download and install it

Create Or Modify .htaccess Files

The .htaccess file is a special hidden file that contains various settings you can use to modify the server behavior, right down to a directory specific level. If the php.ini method didn’t work, I suggest you try this next.

First of all, using FTP or an SSH connection, take a look at your root directory and see if there is an .htaccess file there. If there is you can edit that file to add the necessary code for increasing the upload limit.

php_value upload_max_filesize 12M
php_value post_max_size 13M
php_value memory_limit 15M

Use The ini_set() PHP Function

I’m not a huge fan of doing this, but if all else fails you can give it a go. I recommend adding the following code to the wp-config.php file:

@ini_set( 'upload_max_size' , '12M' );
@ini_set( 'post_max_size', '13M');
@ini_set( 'memory_limit', '15M' );

 

In theory, you could try adding it to your theme’s functions file or your plugins main file, but this code really has no place in either. As a last resort or an interim solution, it could work though.

Nginx Setup

Nginx is an alternative web server software to good old Apache. It can be a lot faster than Apache which is why highly specialized hosts (like Kinsta) use it on their servers to serve pages. If you are running your website on nginx you’ll need to change your php.ini file as well as your nginx config.

We’ve already discussed how to modify a php.ini file so all we need is the code for the ngnix config:

http {
client_max_body_size 13m;
}

Note that you’ll have a number of settings within the HTTP group. Only change the client_max_body_size parameter to make sure you don’t modify anything unintentionally.

Last but not least, you’ll need to reload some services to make sure the changes are applied. Issue the following commands and you should be all done:

service php5-fpm restart
service nginx reload

Conclusion

Checking if these works is pretty easy. I like to go to the Media section and click on Add New. You should see a little message that says: “Maximum upload file size: 8Mb” for example. The numeric value should change as you modify the settings.

I recommend that you go step-by-step and undo any changes you made that didn’t work. Both .htaccess and php.ini files are similar to the cascading properties of CSS. The post_max_size set in a child directory overwrites the same directive from a parent directory.

This can lead to a lot of confusion if you’ve defined these directives everywhere in an attempt to “make sure it works”.

Hopefully, now you understand a little better on how to change and adjust the WordPress maximum upload file size. If you’ve had a particularly stubborn case of file size limits being stuck let us know how you managed to fix it!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
6 Shares
Tweet
Share
Pin
Share6