413 request entity too large

Published on


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.

Nginx Error 413

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.

Note: You need to identify yourself what version of PHP is installed on the webserver in order to edit that. In our case, it’s PHP 8.0 so we have used directory and location commands for that.

nano /etc/php/8.0/fpm/php.ini

Now find the following directives one by one…


…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.

service php8.0-fpm restart

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.

Published in: .

Leave a Reply

Your email address will not be published. Required fields are marked *


  1. Julia Avatar

    Commented on

    How do I fix this problem and allow image upload upto 2MB in size using nginx web-server working in reverse proxy or stand-alone mode on Unix like operating systems?

    1. AtulHost Avatar

      Commented on

      Hi Julia, the syntax used in the post remains same for the Unix OS too. If you want to allow 2MB of file or image in your case then add following code in nginx.conf inside http directive.

      client_max_body_size 2M;

      After adding this live save nginx.conf and reload/restart Nginx.

      Also follow above tutorial and change values in PHP configs too. In most cases I personally suggest to keep them max 100 MB, because no files are larger than this. But if you self host big files like videos or similar large content, do size them as per your preference.

  2. Francisco Quintero Avatar
    Francisco Quintero

    Commented on

    You’re a life saver man, many thanks!