Skip to content

/config/php/upload-max-filesize

php.ini upload_max_filesize and post_max_size: increase the upload limit

The commands on this page have not been executed by our verification runner yet.updated
tool
PHP
file
php.ini
key
upload_max_filesize
type
size (bytes, or with K, M, G suffix)
default
2M (post_max_size 8M)

upload_max_filesize in php.ini sets the largest file PHP accepts in one upload field; the default is 2M. To allow bigger uploads, raise it and post_max_size (the limit for the whole request body, default 8M), which must be at least as large, then restart PHP-FPM or the web server. Both use sizes such as 64M or 1G.

Set the limits

php.ini
upload_max_filesize = 64M
post_max_size = 72M        ; >= upload_max_filesize, plus room for other fields and multiple files
max_file_uploads = 20      ; files per request (default 20)
memory_limit = 128M        ; uploads are written to a temp file, not held in memory

Both directives are PHP_INI_PERDIR: they can be set in php.ini, .user.ini (PHP-FPM and CGI), or .htaccess with php_value (Apache mod_php), but not with ini_set() at run time, because the request body is already read when the script starts.

bash
php --ini                                         # which php.ini the CLI uses
php -i | grep -E 'upload_max_filesize|post_max_size'
sudo systemctl restart php8.3-fpm                 # FPM service name depends on distro and version

The web server's PHP can load a different php.ini than the CLI: check with phpinfo() in a page, under "Loaded Configuration File".

What happens when a limit is hit

Limit exceededSymptom
upload_max_filesize$_FILES['f']['error'] is UPLOAD_ERR_INI_SIZE (1); the other fields arrive
post_max_size$_POST and $_FILES are empty; PHP logs a "POST Content-Length ... exceeds the limit" warning
MAX_FILE_SIZE form field$_FILES['f']['error'] is UPLOAD_ERR_FORM_SIZE (2)
Web server body limitThe server answers 413 before PHP runs (nginx client_max_body_size, default 1m)

Sources