The cart is empty

In this article, we'll delve into the process of setting the upload size limit on a CentOS 7 server running Nginx and PHP-FPM. Adjusting the upload size limit is useful for controlling the size of files users can upload to the server and can help prevent server overload from large files. Implementing this change requires modifications to configuration files for both Nginx and PHP-FPM.

1. Modifying the Nginx Configuration File

Nginx uses the client_max_body_size directive to limit the size of the request body that can contain uploaded files. The default value is usually 1M (1 megabyte). To change this limit, you need to modify the configuration file for your server or location.

Step 1: Open the Nginx Configuration File.

Nginx configuration files are typically located in /etc/nginx/nginx.conf or in the directory /etc/nginx/conf.d/ for specific server configurations. Open the file using a text editor like vim:

sudo vim /etc/nginx/nginx.conf

Step 2: Add or Modify the client_max_body_size Directive.

Locate the http, server, or location section where you want to apply the limit and add or modify the client_max_body_size directive to match the desired maximum upload size. For example, for a limit of 100 megabytes:

client_max_body_size 100M;

Step 3: Restart Nginx.

To apply the changes, restart Nginx:

sudo systemctl restart nginx

2. Modifying the PHP-FPM Configuration File

PHP also limits the size of uploaded files using the upload_max_filesize and post_max_size directives in the php.ini configuration file.

Step 1: Locate the php.ini Configuration File.

The location of the php.ini file depends on the PHP version you are using. You can use the following command to find the location:

php --ini

Step 2: Modify php.ini to Change the Limits.

Open the php.ini file in your preferred editor and find the upload_max_filesize and post_max_size directives. Set them to the desired maximum upload size. For example, for a limit of 100M:

upload_max_filesize = 100M
post_max_size = 100M

Step 3: Restart PHP-FPM.

To apply the changes, restart the PHP-FPM service:

sudo systemctl restart php-fpm

By configuring upload size limits in Nginx and PHP-FPM configuration files, you can effectively control the size of files users can upload to your server. These settings help ensure that the server isn't overwhelmed by large files, which can lead to instability or reduced performance. After making these changes, it's always important to restart the relevant services to apply the new configuration.