Changing upload limits in PHP and nginx

Sometimes when I install a new web server with nginx and php-fpm I run into the problem where my file upload limit is set to 2 MB or less.

This post is to remind me of all the settings that need to be changed to allow uploading files larger than 2 MB.

In PHP there are two settings in php.ini that need to be changed:

  • upload_max_filesize sets the maximum size of an uploaded file. It defaults to 2M.
  • post_max_size sets the maximum size of POST data sent from the browser. Due to encoding, the actual limit of uploaded data will be a bit smaller than this. It can be set to 0 to disable the limit.

There’s also a well-hidden setting in nginx that affects file uploads, that isn’t in any of the sample configuration files and is almost never mentioned anywhere. It also needs to be set.

  • client_max_body_size defaults to 1m. It sets the limit on the size of the request body that can be uploaded, and can be set to 0 to disable it.

So, to finish up, I will decide how large I want the limit of uploaded files to be, and set these limits as in the examples here:

In php.ini:

post_max_size = 0
upload_max_filesize = 128M

In nginx.conf, or in an included file:

client_max_body_size 0;

Leave a Comment

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