The Settings That Matter
- upload_max_filesize: the largest single file PHP accepts. Default 2M.
- post_max_size: the largest whole request, files and form fields together. Default 8M. PHP's documentation says it must be larger than upload_max_filesize.
- memory_limit: the memory one script may use. Default 128M. PHP's documentation advises keeping it larger than post_max_size, and image processing after the upload needs room too.
- max_execution_time and max_input_time: how long a script may run and how long PHP may spend reading the request. Raise them if large uploads arrive over slow connections.
- max_file_uploads: how many files one request may carry.
Find the Right php.ini
On Debian and Ubuntu, each way of running PHP has its own php.ini:
| Used by | File |
|---|---|
| PHP-FPM | /etc/php/8.3/fpm/php.ini |
| Apache module | /etc/php/8.3/apache2/php.ini |
| Command line | /etc/php/8.3/cli/php.ini |
Replace 8.3 with your version (php -v). php --ini shows only the command-line files, so a value it reports says nothing about your website. Nginx always uses PHP-FPM; Apache uses the module unless you set it up with PHP-FPM. On AlmaLinux and Rocky Linux there is one /etc/php.ini plus /etc/php.d/, and Apache uses PHP-FPM by default. See what is PHP-FPM.
Set the New Values
A small file of your own in the conf.d folder keeps your changes apart from the distribution's php.ini. For PHP-FPM on Debian and Ubuntu:
sudo nano /etc/php/8.3/fpm/conf.d/99-uploads.ini
upload_max_filesize = 64M
post_max_size = 72M
memory_limit = 256M
max_execution_time = 120
For the Apache module, the folder is /etc/php/8.3/apache2/conf.d/; on AlmaLinux and Rocky Linux, /etc/php.d/. For one site only, set the values in its PHP-FPM pool file instead, for example php_admin_value[upload_max_filesize] = 64M.
Apply the Change
sudo php-fpm8.3 -t
sudo systemctl reload php8.3-fpm
On AlmaLinux and Rocky Linux: sudo php-fpm -t, then sudo systemctl reload php-fpm. A reload is enough, because the PHP-FPM master process starts over with the new php.ini values without stopping the service; restart only if the old values remain. With the Apache module, run sudo apachectl configtest, then sudo systemctl reload apache2; a reload lets running requests finish.
Check That PHP Uses the New Values
echo '<?php echo ini_get("upload_max_filesize"), " ", ini_get("post_max_size");' | sudo tee /var/www/example.com/limits.php
curl https://example.com/limits.php
sudo rm /var/www/example.com/limits.php
The output should read 64M 72M. A phpinfo() page shows the same values and the Loaded Configuration File, but delete any such test file immediately: it shows paths and settings to anyone.
Raise the Web Server's Limit
Nginx refuses request bodies larger than client_max_body_size, 1 MB by default, with 413 Request Entity Too Large, before PHP sees them. Set it in the server block, slightly above post_max_size:
client_max_body_size 80M;
Then run sudo nginx -t and sudo systemctl reload nginx.
Apache limits request bodies with LimitRequestBody, a size in bytes. Since Apache 2.4.54 the default is 1073741824 bytes (1 GB); in 2.4.53 and earlier it was 0, which means no limit. If a value lower than your uploads is set, Apache rejects the request with an error, usually 413. Look for it with sudo grep -ri limitrequestbody /etc/apache2/ (or /etc/httpd/), and raise it in the virtual host, for example LimitRequestBody 75497472 for 72 MB. Test and reload. A proxy or CDN in front of the server may have its own limit as well.
Troubleshooting
- The old value still shows: you edited another php.ini than the one in use, or PHP-FPM was not reloaded.
- 413 error: the web server's limit, not PHP's.
- The form arrives empty: the request exceeded post_max_size, so PHP left $_POST and $_FILES empty; the PHP log usually has a warning about the size.
- The upload stops partway: raise max_input_time and max_execution_time, and check that the temporary folder has room; see how to check disk space in Linux.
For WordPress on Nginx, the same limits appear in how to install WordPress with Nginx.