How to Fix the 413 (Payload Too Large) Error in Laravel
Table Of Contents
Why Laravel returns a 413 (payload too large) error on POST or file upload, and how to raise the limit in php.ini.
Error Message
Sending a large POST request — a file upload, for example — can return an error like this:
413 Payload Too Large413 Request Entity Too LargePersonally, I run into this one on pretty much every project I build.
Cause (the file size exceeds the limit)
Every server, local or production, has a configured limit on "how much data can be sent in a POST request" and "how large an uploaded file can be."
Without a limit, someone could crash the server just by sending an absurdly large file, so a moderate default limit is set.
In PHP, this limit comes from two php.ini values:
upload_max_filesize
post_max_sizeupload_max_filesize: the max size of a single uploaded filepost_max_size: the max size of the entire POST request (the file plus any other form data)
If the file you're sending exceeds either of these, you get a 413 error.
Checking the Current Limits
PHP has a built-in function for this — the following code dumps your server's configuration:
<?php phpinfo() ?>Add it to a Blade file on the page where the error happens.
Loading the page dumps a long list of PHP server info.
Look for these in there:
upload_max_filesizepost_max_sizeLoaded Configuration File← where the config file lives
That shows you the current values.
upload_max_filesize 30M 30M
post_max_size 30M 30M
/usr/local/etc/php/7.4/php.iniSolution (What Actually Fixed It for Me)
I often deal with large files like videos, so I fixed this by raising both limits to 30M with some headroom.
I used the config file path from the step above (back in 2020 I was on PHP 7.4, but the process is the same regardless of PHP version).
The path will differ by PHP version — use whatever path phpinfo()'s Loaded Configuration File shows for your own environment.
There were only two lines to change, so I just edited the file directly with Vim (the path below is the one from my environment at the time):
vim /usr/local/etc/php/7.4/php.iniOnce Vim is open:
- In normal mode, press
/to search, then look for/upload_max_filesize - Once you find
upload_max_filesize, pressato enter insert mode and change the number (e.g. 8M → 30M) - Press
ESCto go back to normal mode - Press
/again to search forpost_max_size - Once you find
post_max_size, pressato enter insert mode and change the number - Press
ESCto go back to normal mode - Type
:wqto save and quit - Restart your local server (or the server itself, e.g. EC2)
Finally, reload the page running phpinfo() — if the values changed, the update worked.
For a local environment (PHP's built-in server, etc.), this was enough to resolve the 413 error.
Reference: Production (nginx/Apache)
I've only confirmed this fix in a local environment. From what I researched, if you're running nginx or Apache as a reverse proxy in production, there's reportedly a separate upload-size limit on the web server side, in addition to php.ini.
For nginx, that's the client_max_body_size directive.
client_max_body_size 30M;Apparently, if nginx's limit is still lower than your file, you'll keep getting a 413 even after raising the php.ini values — worth checking if the production fix doesn't take effect.
For Apache, the equivalent is reportedly LimitRequestBody.
LimitRequestBody 31457280(Apache uses bytes, so 30MB works out to 30 * 1024 * 1024 = 31457280.)
Both apparently require a restart of the web server after changing the setting.
If You're Using Docker
My project's directory structure looks like this:
project/
└── docker/
└── app/
├── Dockerfile
└── php.iniAdd a line to the Dockerfile to copy in the config file:
COPY ./docker/app/php.ini /usr/local/etc/php/php.iniAdjust the ./docker/app/php.ini part to match your own directory structure.
./docker/app/php.ini
upload_max_filesize = 30M
post_max_size = 30MRun docker compose up -d to restart, and you're good once it's reflected.
What to Include When Asking an AI Chat Tool
If you're asking an AI chat tool (ChatGPT, Claude chat, etc. — not an agent that can run commands itself), pasting the following gets you a much more accurate answer:
- The full error message (including whatever shows in your browser dev tools' Network tab response)
- The size of the file you're trying to upload
- The current
upload_max_filesize/post_max_sizevalues fromphpinfo() - Your environment (PHP's built-in local server, or production behind nginx/Apache)
- If production, whether you're behind a reverse proxy (nginx/Apache) and the relevant part of its config
- If using Docker, the PHP-related parts of your Dockerfile or docker-compose.yml
- Where exactly the 413 happens (on form submission, or before Laravel's validation even runs)
File size and environment (local vs. production, reverse proxy or not) are almost always essential for narrowing down the cause.
Summary
A 413 error means the file you're sending exceeds PHP's upload_max_filesize and/or post_max_size.
Check the current limits with phpinfo(), edit php.ini to raise them, and you're done.
If you're behind nginx or Apache in production, there's a separate limit on the web server side too — check that if raising php.ini alone doesn't fix it.




