413 Request Entity Too Large and PHP Execution Time

To totally unlock this section you need to Log-in

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, we will see how to fix this error “413 request entity is too large” in Apache as well as in Nginx, Microsoft IIS, and definitely in PHP as well.

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

As stated in Nginx manual, The client_max_body_size directive assigns the maximum accepted body size of client request, indicated by the line Content-Length in the header of request. If size is greater the given one, then the client gets the error "Request Entity Too Large (413)".

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

sudo service apache2 reload

Now fix PHP limits as well to fix this issue: see below in this article to see how to do it.

Nginx Users: Fix 413 Request Entity Too Large

It can be fixed by increasing the memory limit in Nginx as well as PHP configuration file. In order to fix this issue, we need to edit nginx.conf file.

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

sudo service nginx restart

Now fix PHP limits as well to fix this issue: see below in this article to see how to do it.

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 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. Below an example involving the PHP 7.3 version:

nano /etc/php/7.3/fpm/php.ini

Now find following directives one by one:


...and increase its limit to 100M, by default they are 8M and 2M.

  • upload_max_filesize defines the maximum allowed size for uploaded files.
  • post_max_size defines the maximum size of POST data that PHP will accept.
upload_max_filesize = 100M
post_max_size = 100M

Finally, save it and restart the PHP (in this example is PHP 7.3 FPM.

service php7.3-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.

For IIS Users (Microsoft Windows Server)

The quickest solution is to increase the upload size limit. IIS uses uploadReadAheadSize parameter in applicationHost.config and web.config files to control this limit.

uploadReadAheadSize: Specifies the number of bytes that a Web server will read into a buffer and pass to an ISAPI extension or module. This occurs once per client request. The ISAPI extension or module receives any additional data directly from the client. The value must be between 0 and 2147483647. The default value is 49152.

Steps to change the value of this parameter:

  • Open IIS Manager.
  • Select the site.
  • Double click “Configuration Editor”.
  • Select system.webServer and then serverRuntime.
  • Modify the uploadReadAheadSize value.
  • Click “Apply”.

413 Request Entity Too Large and PHP Execution Time

You may also want to change maxRequestEntityAllowed parameter. It specifies the maximum number of bytes allowed in the request body.

Using the command line, on IIS Server, we could use both appcmd.exe and Powershell approaches, as the following:

appcmd.exe set config -section:system.webServer/serverRuntime /uploadReadAheadSize:"491521" /commit:apphost

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/serverRuntime" -name "uploadReadAheadSize" -value 2147483647

Remember that the uploadReadAheadSize value must be between 0 and 2147483647.