If you are using Laravel Homestead and you are developing an application where you need to upload large images or files, you may run into the following error:
413 Request Entity Too Large
This is an Nginx warning and it means you are uploading a file that exceeds the max upload size defined in your nginx.conf. The default values are a bit low and if you are developing an application where you need to upload large files you may run into this. Luckily, it’s a very quick and easy fix! You need to change the client_max_body_size to an higher value, for example 100MB. Here’s how you change it:
- SSH in your Laravel Homestead system (you need to use sudo because you need admin privileges):
sudo nano /etc/nginx/nginx.conf
- Add this line in the http section (the actual place it not really important, I added this between server_tokens and server_names_hash_bucket_size):
client_max_body_size 100M;
Pay attention to the M, don’t use MB.
- Finally:
sudo systemctl restart nginx
Test the changes you have just made, you now should be able to upload larger files to your application. If you are still receiving this Laravel Homestead Request Entity Too Large error, verify the changes you have just made. Maybe you used MB instead of M? Or if you are trying to upload a file larger than 100 MB, change the above value accordingly. When your application is ready, also verify that you made this change on your production server otherwise users may run into this issue again.
Great! You have fixed this Laravel Homestead Request Entity Too Large warning and can now further develop your application.
About Laravel Homestead
Laravel Homestead is an amazing free development environment that is based on Vagrant with VirtualBox or Parallels. It contains all the software you need for developing Laravel applications. If you mess something up you can destroy and recreate the development environment in minutes. This has huge advantages, for example you don’t need to install every development tool locally on your system, but just install Laravel Homestead and it contains everything you need.
- More info about Laravel Homestead can be found in the official documentation and on GitHub.