Category: Advanced – Command Line • Est. reading time: 1 minute
By default, large file uploads can fail on an Nginx server, often with a “413 Request Entity Too Large” error. That is because the size limit is set in two separate places, PHP and Nginx, and you have to raise both. This guide is for people managing their own server over SSH as root or with sudo.
Step 1: Find and Open Your php.ini
First, find which php.ini your server actually loads:
php --ini
Look for the “Loaded Configuration File” line, then open that file in your editor. Your path will match what the command reported:
sudo vi /etc/php/8.2/fpm/php.ini
Step 2: Raise the PHP Limits
Find these two lines and set them to the size you want. Keep post_max_size at least as large as upload_max_filesize:
upload_max_filesize = 128M
post_max_size = 128M
If you set a very large size, also make sure memory_limit, also in php.ini, is at least as large.
Step 3: Restart PHP-FPM
sudo systemctl restart php-fpm
On Ubuntu or Debian the service name usually includes the version, such as php8.2-fpm.
Step 4: Raise the Nginx Limit
Nginx has its own cap. Open your site’s vhost file:
sudo vi /etc/nginx/sites-available/yoursite.com
Inside the server block, add or update this line:
client_max_body_size 128M;
Step 5: Test and Reload Nginx
Always test the config first so a typo cannot take the site down, then reload:
sudo nginx -t
sudo nginx -s reload
Running your own dedicated or self-managed server? We are glad to help. Reach us at support@allydrez.com or 1-321-209-2004.