The error “413 Request Entity Too Large” is a very common error that occurs with Apache or Nginx web servers. It appears when someone requests more information than is limited by Apache or Nginx and by PHP configurations.
It can be found on standalone Apache/Nginx web server or while proxy-based solutions when NGINX acts as a front end server for Apache at back end server.
In this guide, I will explain how to fix this error “413 request entity is too large” in Apache as well as in Nginx, and definitely in PHP as well.
When It Occurs?
As the error says request entity too large, it occurs when a request made by the client is large and trying to access or process more information than what is limited by Apache/Nginx and PHP configuration file. Mostly it occurs when you have everything set up in default mode (means just installed software and left all settings as it is).
How To Fix “413 Request Entity Too Large” Errors?
Here we need to allow more memory to the webserver to fix this issue.
Apache Users: Fix 413 Request Entity Too Large.
Edit .htaccess
file and add the below directive in it.
LimitRequestBody 104857600
Now restart Apache.
service apache2 reload
Now fix PHP limits as well to fix this issue.
Nginx Users: Fix 413 Request Entity Too Large.
It can be fixed by increasing the memory limit in Nginx as well as the PHP configuration file. In order to fix this issue, we need to edit nginx.conf
file.
nano /etc/nginx/nginx.conf
Search for this variable: client_max_body_size
.
If you find it, just increase its size to 100M
, for example. If it doesn’t exist, then you can add it inside and at the end of http { ... }
block.
client_max_body_size 100M;
Restart the Nginx to apply the changes.
service nginx restart
Now fix PHP limits as well to fix this issue.
Modify PHP.ini File To Increase Upload Limits.
It’s not needed on all configurations, but you may also have to modify the PHP upload settings as well to ensure that nothing is going out of the limit by PHP configurations.
Here, we need to edit the php.ini file. It is where you declare changes to your PHP settings.
The server is already configured with standard settings for PHP, which your website will use by default. Unless you need to change one or more settings, there is no need to create or modify a PHP.ini file.
Note: You need to identify yourself what version of PHP is installed on the web server in order to edit that. In our case, it’s PHP 8.0 so we have used directory and location commands for that.
sudo nano /etc/php/8.0/fpm/php.ini
Now find the following directives one by one…
upload_max_filesize
post_max_size
…and increase its limit to 100M, by default they are 2M and 8M.
upload_max_filesize = 100M
post_max_size = 100M
Finally, save it and restart the PHP.
sudo systemctl restart php8.0-fpm
You can set any limit to Apache/Nginx and PHP configuration files, here we have set them to 100M means 100 MegaBytes which is more than enough what we needed.
Leave a Reply