Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Livewire uploads work locally but fail behind nginx on the server

Error413 Request Entity Too Large

Short answer

Three separate limits stop a large upload, and a local dev server hides two of them. nginx rejects bodies over 1 MB by default, PHP accepts only 2 MB per file and 8 MB per request by default, and Livewire validates temporary uploads against a 12 MB rule. Raise each one to match, reload the services, and test with a file near your real maximum.

  • Applies to Livewire 3, Laravel 12, nginx 1.26, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Upload a file in the browser with the network tab open and read the status of the upload request. A 413 comes from nginx. Anything else means PHP or Livewire.

    sudo tail -n 20 /var/log/nginx/error.log
  2. 2Match what you see, then jump to its fix

    1. 1413 Request Entity Too Large in the browser's network tabnginx rejects the request body (default 1 MB)Fix
    2. 2The request reaches PHP but the upload is empty, or only files over 2 MB fail after nginx was fixedPHP limits are lower than the fileFix
    3. 3nginx and PHP accept the request, but a file over 12 MB fails validationLivewire's own temporary-upload rule (12 MB)Fix

What does the error look like?

  • 413 Request Entity Too Large
  • $_POST and $_FILES are empty (PHP discards a body over post_max_size)
  • Small files upload, larger ones fail

Cause 1 of 3

nginx rejects the request body (default 1 MB)

1Check

client_max_body_size defaults to 1m. When the body is bigger, nginx answers 413 before PHP sees the request.

grep -R "client_max_body_size" /etc/nginx/

2Fix

Set a limit above your largest upload, in the http, server or location block that serves the app. Then test the config and reload nginx.

server {
    client_max_body_size 20m;
}

3Verify

Reload nginx and upload the file that failed.

sudo nginx -t && sudo systemctl reload nginx

Confirmed by nginx.org

Did this fix it?

Cause 2 of 3

PHP limits are lower than the file

1Check

upload_max_filesize defaults to 2M and post_max_size to 8M. If the whole request is bigger than post_max_size, PHP leaves $_POST and $_FILES empty. post_max_size must be larger than upload_max_filesize. Read the values the web service uses, not only the command line: the CLI can load a different php.ini.

php -i | grep -E 'upload_max_filesize|post_max_size'

2Fix

Raise both values in the php.ini that PHP-FPM loads (find it in the phpinfo() output of a page served by the site), keeping post_max_size larger, then restart PHP-FPM.

upload_max_filesize = 20M
post_max_size = 25M
; sudo systemctl restart php8.3-fpm

3Verify

Upload a file just under 20 MB and confirm it is accepted.

sudo systemctl restart php8.3-fpm

Confirmed by php.net

Did this fix it?

Cause 3 of 3

Livewire's own temporary-upload rule (12 MB)

1Check

Livewire validates every temporary upload with a default rule that allows files up to 12288 kilobytes. Your component's own rules (for example max:1024) are checked later and are separate.

grep -n "temporary_file_upload" -A8 config/livewire.php

2Fix

Publish the config if the file does not exist, then set a rule that matches your limits, and keep it below the nginx and PHP values.

php artisan livewire:config

// config/livewire.php
'temporary_file_upload' => [
    'rules' => 'file|mimes:png,jpg,pdf|max:20480',
],

3Verify

Clear the cached config and upload a file between 12 MB and 20 MB.

php artisan config:clear

Confirmed by livewire.laravel.com

Did this fix it?

How do I stop it coming back?

  • Write the three limits (nginx, PHP, Livewire) next to each other in your deploy notes and change them together.
  • Keep post_max_size larger than upload_max_filesize, and the nginx limit larger than both.
  • After any change to the nginx or PHP-FPM config, reload the service, not only the app.
  • Test every deploy with a file near your largest allowed size, not a 100 KB image.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

PHP stops the script after 30 seconds

Symfony\Component\ErrorHandler\Error\FatalError: Maximum execution time of 60 seconds exceeded

PHP ends a script that runs past max_execution_time (30 seconds by default for web requests).

5 causes, each with a fix

Back end

CodeIgniter works locally but every page is 404 on the live server

The requested URL was not found on this server.

A 404 on the live server comes from one of four places: the document root is not the public folder, Apache ignores .htaccess or nginx has no try_files rule, the route is not defined because auto routing is off, or the controller file name differs from its class in case.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.