First, accept my apologies for the previous message, I had a typo in the html file when I reproduced the 413 error message. I investigated this further, and I found that I get the 413 error code and the message on browser when the
upload.html has a typo. For example, when the form definition points to a non-existent file. In my case, I originally created a
uploads.php file instead of
upload.php as mentioned in the HTML.
<form action="upload.php" method="post" enctype="multipart/form-data">
Can you check that if you make this typo on purpose, you get the 413 error code as well?
Apart from that, I reproduced your issue on Apache returning 200 ok even if the file is larger than expected. However, I’m getting an error in the Apache log for this.
==> apache2/logs/error_log <== [Tue Jun 08 09:08:14.824315 2021] [proxy_fcgi:error] [pid 2773:tid 140241646069504] [client MY_IP_ADDRESS:52007] AH01071: Got error 'PHP message: PHP Warning: POST Content-Length of 5243179 bytes exceeds the limit of 2097152 bytes in Unknown on line 0PHP message: PHP Notice: Undefined index: fileToUpload in /opt/bitnami/apache/htdocs/upload.php on line 3PHP message: PHP Notice: Trying to access array offset on value of type null in /opt/bitnami/apache/htdocs/upload.php on line 3PHP message: PHP Notice: Undefined index: fileToUpload in /opt/bitnami/apache/htdocs/upload.php on line 26PHP message: PHP Notice: Trying to access array offset on value of type null in /opt/bitnami/apache/htdocs/upload.php on line 26', referer: http://184.108.40.206/upload.html ==> apache2/logs/access_log <== MY_IP_ADDRESS - - [08/Jun/2021:09:08:14 +0000] "POST /upload.php HTTP/1.1" 200 94
After that, I disabled PHP-FPM following the next guide plus adding an additional code snippet at the end of the
The snippet is
# PHP 7 module specific configuration <IfModule php7_module> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> </IfModule>
Then, restart Apache. It now returns 413 error when the file is larger than the configured value, and 200 ok when it is smaller. Can you check if you reproduce the same behavior?
I suspect the 200 ok when using PHP-FPM is due to the Apache and PHP-FPM connection being properly done. Unfortunately, I don’t know how to raise an error in the case of using PHP-FPM and uploading a bigger file. I guess you can check it from the PHP code and return a 413 error in that case.