Increase file upload size limit (PHP – Nginx)

Send Us a Sign! (Contact Us!)

If Nginx aborts your connection when uploading large files, you will see something like below in Nginx’s error logs:

[error] 25556#0: *52 client intended to send too large body:

This means, you need to increase PHP file-upload size limit. Following steps given below will help you troubleshoot this!

Changes in php.ini

To change max file upload size to 100 MB, edit as following:

vim /etc/php5/fpm/php.ini

Set the following parameters (modify them following your needs):

upload_max_filesize = 100M
post_max_size = 100M

Notes

  • Technically, post_max_size should always be larger than upload_max_filesize but for large numbers like 100M you can safely make them equal. To be sure, add few megabytes to post_max_size value.
  • There is another variable max_input_time which can limit upload size but it should not give any issue. If your application supports uploads of file-size in GBs, you may need to adjust it accordingly. Usually, as Nginx to PHP "copying" will be local operation max_input_time may never create issues.

Change in Nginx config

Add following line to http{..} block in nginx config:

http {
	#...
        client_max_body_size 100m;
	#...
}

NOTE: For very large files, you may need to change value of client_body_timeout parameter. Default is 60s.

Reload PHP-FPM & Nginx

service php5-fpm reload
service nginx reload

Changes in WordPress-Multisite (Example)

If you are running WordPress Multisite setup, then you may need to make one more change at the WordPress end.

Go to: Network Admin Dashboard >> Settings. Look for Upload Settings; change value for Max upload file size:

Increase file upload size limit (PHP - Nginx)