Fix 413 Request Entity Too Large in WordPress

This tutorial outlines how to solve a common WordPress error – “413 Request Entity Too Large” encountered when files, media, or data upload exceeds the web server’s limit. It suggests increasing the server’s request size limit, adjusting Apache2 and PHP-FPM configurations to allow larger uploads, modifying WordPress directory permissions, and restarting Apache2 to apply these…

This brief tutorial shows students and new users how to resolve a common error with WordPress when trying to upload files, media, and other data and get shown an error that says “413 Request Entity Too Large” via the Apache2 HTTP server.

This error, 413 request entity too large, occurs when you try to upload or make a client request that is too large to be processed by the web server, in the case of an Apache2 HTTP server.

If the server setting has a request size limit that is too small, your users/clients may come across this error a lot. So, you will probably want to adjust the web server settings to allow larger requests.

WordPress allows users to upload new themes and plugin files; however, if your Apache2-powered website isn’t configured to allow the large file to be uploaded, the upload process will always fail.

Some common errors users get when dealing with file uploads with WordPress are Http errors attempting to upload media, the uploaded file exceeding the upload_max_filesize directive in php.ini, maximum execution time exceeded, allowed memory size exhausted, and many more.

Before continuing with the steps below, please back up your system.

Configure WordPress Directory Permissions

First, ensure the directory WordPress is running in has the correct permission for the Apache2 web server to operate. On Ubuntu systems, the root directory is almost always at /var/www/html.

So, run the commands below to give Apache2 web server full access to that directory.

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Adjust PHP-FPM Settings

Next, adjust PHP-FPM settings to allow larger file uploads. By default, PHP-FPM is only allowed to upload a specific file size. So there’s a limit. Adjust the file upload size limit and other directives in PHP-FPM.

On Ubuntu 18.04 and up, the default PHP-FPM configuration file is stored in the file below:

/etc/php/7.2/apache2/php.ini

The x in the line above can either be a 0 or 1, 2, 3 or 4

So, open the PHP-FPM configuration file by running the commands below and adjusting the settings to suit your environment.

sudo nano /etc/php/7.2/apache2/php.ini

Then scroll down the file line by line and adjust each directive with the value below:

memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 100M
file_uploads = On
max_execution_time = 600
max_input_time = 600

Save your changes.

If the file size you’re uploading is more significant than 100MB, then adjust the upload_max_filesize to be greater than the file size.

Adjust Apache2 Configuration

Apache2 also has limited definitions.

If you don’t define the size limit in the Apache2 configuration, whatever you do in the PHP configuration file may not apply to Apache2. To allow Apache2 also to upload a larger file, open Apache2 configuration and add the values as defined below:

Apache2 default site configuration files on Ubuntu systems are stored at /etc/apache2/apache2.conf

Open the configuration file and, add the highlighted line, then save.

sudo nano /etc/apache2/apache2.conf
Add the line, then save.
#
Timeout 300
#
LimitRequestBody 104857600
#
KeepAlive On
#
MaxKeepAliveRequests 100
#
KeepAliveTimeout 5
#
HostnameLookups Off

Save the file and continue.

Finally, restart Apache2, which will also reload PHP configurations for the new settings to take effect.

sudo systemctl reload apache2.service

This should do it. Now go and try to upload the file you want with a size smaller than 100MB

Enjoy~

You may also like the post below:

Richard Avatar

Comments

Leave a Reply

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