Indonesia Website Awards
Indonesia Website Awards

In my previous article, I discussed how to fix error “504 gateway time-out” in Nginx PHP. For my article this time, I will discuss how to fix error “413 Request Entity Too Large” in Nginx PHP. Before we start, let me explain what caused the error. This error occurs when we are trying to upload a file whose size exceeds the size set by nginx and php. What I know is the default amount we are allowed to upload a file in PHP is 2MB. Therefore, if we upload a file with a size of more than 2MB, the error message will appear. To fix this we need to add the upload size value in the Nginx and php configuration, here’s how:

 

Step 1: Update the php.ini file

First, we can update the parameters in the php.ini file to increase the value, there are 3 parameters that we update, namely:

  • memory_limit – which I know this parameter specifies the maximum amount of memory (RAM) in bytes that a php script can allocate,
  • upload_max_filesize – this parameter specifies the maximum file size we can upload,
  • post_max_size – this parameter specifies the maximum limit of allowed post data, I suggest a value equal to / greater than the upload_max_filesize parameter.

Alright, we just go to the php.ini file, previously if we don’t know where it is, we can search it with the

find
find command as follows

find / -name 'php.ini'
find / -name 'php.ini'

then go straight to your favorite editor

vim /etc/php/7.3/fpm/php.ini
vim /etc/php/7.3/fpm/php.ini 

find and set the three parameters that I have mentioned according to your needs, for example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
memory_limit = 128M
upload_max_filesize = 10M
post_max_size = 11M
memory_limit = 128M upload_max_filesize = 10M post_max_size = 11M
memory_limit  = 128M 

upload_max_filesize  = 10M 

post_max_size  = 11M

 

Step 2 – Update the Nginx configuration

Now in the PHP section, we now turn to the Nginx section. Just like in the previous article, you can add it to the nginx.conf file for universal use or you can customize it by adding it in the * .conf file you have.

For the nginx.conf file, you can add it to the

http {..}
http {..} section by entering the client_max_body_size parameter along with the values ​​as in the php configuration. Examples like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
http {
...
client_max_body_size 10M;
...
}
http { ... client_max_body_size 10M; ... }
http {
      ...
      client_max_body_size 10M;
      ...
}

Then if you want to add it in the * .conf file you can add these parameters to the 

server {..}
server {..} section. Examples like this :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
server {
...
client_max_body_size 10M;
...
}
server { ... client_max_body_size 10M; ... }
server { 
         ... 
         client_max_body_size 10M; 
         ... 
}
Step 3 – Reload / restart the nginx service and also php-fpm

For the last, after you set the configuration of the three steps above, you only need to restart the service by:

systemctl restart nginx
systemctl restart nginx

systemctl restart php-fpm
systemctl restart php-fpm

After restarting, try to test again by uploading a file. Then the error no longer appears and the file has been successfully uploaded.

Yep, that’s the information I can share about how to fix error  “413 Request Entity Too Large” in Nginx PHP. Hopefully this information can be useful, Thank you 😆

Also Read :

 


0 Comments

Leave a Reply

Avatar placeholder

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