What the message looks like
The uploaded file exceeds the upload_max_filesize directive in php.ini
PHP Warning: POST Content-Length of 52428900 bytes exceeds the limit of 8388608 bytes in Unknown on line 0Common causes
upload_max_filesizein thephp.iniof PHP-FPM is smaller than the file.post_max_sizeis smaller than the upload plus other form data (then$_FILESis silently empty).- nginx
client_max_body_sizeis smaller and answers 413 before PHP sees the file. - The setting was changed in the CLI
php.iniinstead of the FPM one. - A pool or
.user.inioverrides the global value, or the upload is so slow thatmax_input_timeormax_execution_timeends it.
Check
- Effective values in the FPM php.ini
grep -E '^(upload_max_filesize|post_max_size|memory_limit|max_input_time|max_execution_time) *=' /etc/php/*/fpm/php.ini - Overrides in conf.d and pools
grep -rEn 'upload_max_filesize|post_max_size' /etc/php/*/fpm/conf.d/ /etc/php/*/fpm/pool.d/ - The nginx limit
nginx -T 2>/dev/null | grep -n 'client_max_body_size' - What does the web server return for a large body? (look at the status line)
curl -s -o /dev/null -w '%{http_code}\n' -X POST --data-binary @/etc/services https://example.com/upload.php
Fix
- Create a drop-in
/etc/php/<version>/fpm/conf.d/99-upload.iniwithupload_max_filesize = 64Mandpost_max_size = 72M. The second value must be larger than the first. - Make sure
memory_limitis not smaller thanpost_max_sizeif the application loads the file into memory. - In nginx set
client_max_body_size 72M;(inhttp,serveror the uploadlocation). - Restart the PHP-FPM service of your version and reload nginx:
nginx -t && systemctl reload nginx. - For slow connections also raise
max_input_timeandmax_execution_time.
FAQ
Why must post_max_size be bigger than upload_max_filesize?
The POST request contains the file plus form fields and encoding overhead. If it exceeds post_max_size, PHP drops the whole request body.
Does .htaccess help on nginx?
No. nginx ignores .htaccess. Use the php.ini drop-in, or php_admin_value in the pool file.