How to Successfully Increase PHP Upload Limit Beyond 120MB in nginx

How to Successfully Increase PHP Upload Limit Beyond 120MB in nginx

blogize

54 года назад

8 Просмотров

Learn how to resolve the "413 Request Entity Too Large" error in nginx by increasing the PHP upload limit beyond 120MB.
---
When working with servers using nginx and PHP, you may encounter the "413 Request Entity Too Large" error. This typically occurs when users try to upload files that exceed the server's configured limitations. Fortunately, it's possible to increase the PHP upload limit beyond 120MB by adjusting the nginx and PHP settings accordingly. Here’s a step-by-step guide on how to achieve this.

Understanding the Error

First, it’s important to understand why the "413 Request Entity Too Large" error occurs:

Nginx Configuration: Nginx has a default client body size limit set to 1MB, which might be insufficient for uploading large files.

PHP Configuration: PHP also has its own constraints for upload sizes through directives like upload_max_filesize and post_max_size.

By increasing both nginx’s and PHP’s file upload limits, you can successfully allow larger file uploads without encountering this error.

Step-by-Step Guide

Step 1: Modify Nginx Configuration

Locate the Nginx Configuration File:
The configuration file is usually located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf.

Edit the Configuration File:
Open the file in your preferred text editor, such as vim or nano.

[[See Video to Reveal this Text or Code Snippet]]

Add/Update the Client Body Size Directive:
Locate the http block, and add the following directive to set the client body size limit to 150MB or more.

[[See Video to Reveal this Text or Code Snippet]]

Restart Nginx:
After saving the file, restart nginx to apply the changes.

[[See Video to Reveal this Text or Code Snippet]]

Step 2: Modify PHP Configuration

Locate the PHP Configuration File:
The php.ini file is typically located in /etc/php/7.4/fpm/php.ini or /etc/php/7.4/cli/php.ini.

Edit the php.ini File:
Open the file in your preferred text editor.

[[See Video to Reveal this Text or Code Snippet]]

Update the Upload Limits:
Locate the upload_max_filesize and post_max_size directives and set them to values higher than 120MB.

[[See Video to Reveal this Text or Code Snippet]]

Restart PHP-FPM:
After saving the file, restart the PHP-FPM service to apply the changes.

[[See Video to Reveal this Text or Code Snippet]]

Step 3: Verify the Changes

After making these changes, you should verify that the new upload limits are correctly applied. You can create a test script in PHP to display the current configuration settings and ensure they reflect the new limits.

[[See Video to Reveal this Text or Code Snippet]]

Conclusion

By adjusting the upload limits in both nginx and PHP configuration files, you can easily increase the upload limit beyond 120MB and resolve the "413 Request Entity Too Large" error. This will enable users to upload larger files seamlessly, improving their overall experience on your server.

Тэги:

#413_Request_Entity_Too_Large_nginx #How_can_I_successfully_increase_my_PHP_upload_limit_beyond_120MB_in_nginx? #nginx #php
Ссылки и html тэги не поддерживаются


Комментарии: