Management Guides Troubleshooting
WordPress 413 Request Entity Too Large and upload_max_filesize
Fix "413 Request Entity Too Large" and "exceeds the upload_max_filesize directive" in WordPress on nginx and PHP-FPM by raising three limits in the right files.
WordPress upload failures on a VPS come with one of two messages. "413 Request Entity Too Large" (newer nginx releases word it "413 Content Too Large") is nginx refusing the request before PHP sees it. "The uploaded file exceeds the upload_max_filesize directive in php.ini" is PHP refusing the file after nginx let it through.
Three limits apply to every upload, and the smallest one wins: client_max_body_size in nginx, and upload_max_filesize and post_max_size in the php.ini that PHP-FPM loads. Raise all three, reload both services, and check the figure WordPress shows on the upload screen. If the site is behind Cloudflare, a fourth limit applies that you cannot change on the server.
Directive names, defaults and commands follow the nginx, PHP and WP-CLI documentation. Nothing here was run on a test server for this article.
Which limit did you hit
| What you see | Likely cause | Where to look |
|---|---|---|
| "413 Request Entity Too Large" or "413 Content Too Large"; in the media uploader often only a generic "HTTP error" | nginx client_max_body_size (default 1m) | nginx error log, site server block |
| A 413 on a Cloudflare page | Cloudflare's upload limit for your plan | Cloudflare documentation |
| "The uploaded file exceeds the upload_max_filesize directive in php.ini." | PHP upload_max_filesize (default 2M) | The FPM php.ini |
| Upload fails with no clear message; the PHP log says "POST Content-Length ... exceeds the limit" | PHP post_max_size (default 8M) | The FPM php.ini |
| "exceeds the maximum upload size for this site" | WordPress refusing in the browser, based on the PHP values or the multisite setting | The upload screen |
For a 413, the nginx error log confirms the cause and shows how large the request was:
sudo grep "too large body" /var/log/nginx/error.log | tail -n 3
Raise the nginx limit
client_max_body_size sets the largest request body nginx accepts. It may appear in the http, server or location context; putting it in the site's server block limits the change to that site.
server {
server_name example.com;
client_max_body_size 136m;
...
}
sudo nginx -t && sudo systemctl reload nginx
sudo nginx -T 2>/dev/null | grep client_max_body_size
The second command prints the complete loaded configuration, filtered to this directive. If an older, smaller value shows up in another file, it may be overriding yours. Set the value to match PHP's post_max_size below; a request is always a little larger than the file inside it.
Find the php.ini that PHP-FPM loads
On Ubuntu and Debian, PHP has separate configuration for the command line and for PHP-FPM. Editing /etc/php/8.5/cli/php.ini, which is the file php --ini reports, changes nothing for the website. Ask the FPM binary instead:
# Ubuntu, Debian (use your PHP version)
php-fpm8.5 -i | grep -E "Loaded Configuration File|Scan this dir"
# AlmaLinux, Rocky Linux
php-fpm -i | grep -E "Loaded Configuration File|Scan this dir"
The usual answers are /etc/php/8.5/fpm/php.ini with the directory /etc/php/8.5/fpm/conf.d/ on Ubuntu and Debian, and /etc/php.ini with /etc/php.d/ on AlmaLinux and Rocky Linux, where the command line and FPM share one file.
Raise the PHP limits
Instead of editing php.ini, put the values in a small file of your own in the scanned directory. It survives package updates and is easy to find later. Create /etc/php/8.5/fpm/conf.d/99-uploads.ini (or /etc/php.d/99-uploads.ini on AlmaLinux and Rocky Linux):
upload_max_filesize = 128M
post_max_size = 136M
upload_max_filesize is the limit for one file. post_max_size is the limit for the whole request, which may contain several files and form fields, so the PHP manual requires it to be larger. Then test the configuration, reload and verify:
# Ubuntu, Debian
sudo php-fpm8.5 -t && sudo systemctl reload php8.5-fpm
php-fpm8.5 -i | grep -E "upload_max_filesize|post_max_size"
# AlmaLinux, Rocky Linux
sudo php-fpm -t && sudo systemctl reload php-fpm
php-fpm -i | grep -E "upload_max_filesize|post_max_size"
To set different limits per site, use the pool file instead (/etc/php/8.5/fpm/pool.d/www.conf, or /etc/php-fpm.d/www.conf):
php_admin_value[upload_max_filesize] = 128M
php_admin_value[post_max_size] = 136M
A pool value overrides php.ini, and php-fpm -i does not show it. If the ini files look right and WordPress still reports a small limit, search the pool files: grep -R "upload_max_filesize\|post_max_size" /etc/php/ /etc/php-fpm.d/ 2>/dev/null.
Verify in WordPress
Open Media → Add New Media File (Add New in older versions). Below the upload box WordPress prints "Maximum upload file size", which is the lower of the two PHP values. Tools → Site Health → Info → Server lists both values separately as PHP-FPM sees them.
WP-CLI can print the values too, with a caveat:
cd /var/www/example.com
sudo -u www-data wp eval 'echo ini_get("upload_max_filesize"), " ", ini_get("post_max_size"), PHP_EOL;'
WP-CLI runs under the command-line PHP. On AlmaLinux and Rocky Linux that reads the same php.ini as FPM. On Ubuntu and Debian it reads the CLI configuration, so this shows the website's limit only if you changed both. The upload screen is the reliable check.
On a multisite network there is one more setting: Network Admin → Settings → "Max upload file size", given in kilobytes, which applies on top of the PHP values.
Why .htaccess and ini_set do nothing here
Many instructions say to add php_value upload_max_filesize 64M to .htaccess. That file is read by Apache, and php_value lines in it work only when PHP runs as an Apache module. Nginx ignores .htaccess completely.
Adding ini_set( 'upload_max_filesize', '64M' ); to wp-config.php fails for a different reason. PHP receives and checks the upload before the first line of WordPress runs, and the PHP manual marks both directives as changeable only in configuration files, not from a script. The call returns false and the limit stays.
One per-directory file does work with PHP-FPM: a .user.ini in the site's root folder containing the same two lines. PHP re-reads it every few minutes, so no reload is needed, but a php_admin_value in the pool overrides it. On your own server the files above are the clearer place.
Memory and time for big imports
A large upload that passes all three limits can still fail in the next step. Resizing a very large image or parsing an import file needs memory, and the work may outlast the time limits.
- "Allowed memory size exhausted" in the PHP log: see WordPress memory limit. The PHP manual advises that
memory_limitshould generally be larger thanpost_max_size. - A 504 after the upload reaches 100%: PHP is still processing the file. 504 Gateway Time-out explains
max_execution_timeandfastcgi_read_timeoutand how to raise them for one URL. - Uploads failing at any size: check that the disk is not full, with "No space left on device", and that the web user can write to
wp-content/uploads, with WordPress file permissions.
Cloudflare's upload limit
When the site's DNS record is proxied through Cloudflare, Cloudflare applies its own maximum request size and answers with a 413 before the request reaches your server. Cloudflare's documentation listed 100 MB for the Free and Pro plans and 200 MB for Business when this article was written; check that page for current figures. No server setting changes it. For larger files, bypass the browser as described next.
Huge files: upload by SFTP and import with WP-CLI
For videos, large archives or hundreds of images, skip the HTTP limits entirely. Copy the files to the server over SFTP, into a folder the web user can read, then register them in the media library with WP-CLI:
cd /var/www/example.com
# the web user is www-data on Ubuntu, Debian; nginx or apache on AlmaLinux, Rocky Linux
sudo -u www-data wp media import /srv/incoming/launch-video.mp4 --title="Launch video"
sudo -u www-data wp media import /srv/incoming/*.jpg
wp media import copies each file into wp-content/uploads, creates the attachment and generates image sizes, the same as an upload through the browser. It prints the attachment ID for each file, and the files then appear in the Media Library. Delete the originals from the incoming folder afterwards. Copying a file straight into wp-content/uploads without this step does not work: the library lists only files that have a database record.
A large database dump follows the same idea. Import it with wp db import file.sql from the shell instead of a browser tool.