How to fix the Nginx PHP large file upload error
I have a PHP web application running with php-fpm behind Nginx. This application allows multiple files to be uploaded at once to the server. I tried to upload a few files greater than 2MB and it showed a blank page and various errors like this:
a client request body is buffered to a temporary file /usr/local/var/run/nginx/client_body_temp/0000000001, client: 127.0.0.1, server: ...
and:
client intended to send too large body: 6473667 bytes, client: 192.168.1.202, server: ...
Why was I not able to upload a 3MB file?
By default, Nginx is configured to only allow uploads of 2MB or lesser. Any greater than 2MB and you will see this error in the logs.
The solution was to edit nginx.conf and increase the allowed upload size.
I decided to increase the upload size to 20MB because I did not expect larger files than 20MB.
Solution for Nginx
Edit the nginx.conf file.
On the Mac, nginx.conf is located at /usr/local/etc/nginx/nginx.conf
. On Linux, it is located at /etc/nginx/nginx.conf
.
Edit nginx.conf and look for client_max_body_size
and client_body_buffer_size
.
Add the new upload file size limits to each line, like this:
client_max_body_size 20M;
client_body_buffer_size 20M;
Then, restart Nginx.
sudo systemctl restart nginx
If you are running Nginx as a non-service, do this:
nginx -s stop
nginx
What happened next? PHP blocked large file uploads too
After increasing the Nginx upload size from 2MB to 20MB, I was able to upload files of various sizes -- 3MB, 5MB, 6MB -- until I tried to upload a file greater than 8MB.
It failed when I tried to upload a 11MB file.
This time, the culprit was PHP. There was a file size upload limit set by PHP as well, and it turned out to be 8MB.
2025/07/22 10:00:51 [error] 7005#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning: PHP Request Startup: POST Content-Length of 11773133 bytes exceeds the limit of 8388608 bytes in Unknown on line 0" while reading response header from upstream, client: 192.168.1.202, server: SERVER_NAME, request: "POST /path HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.1.105:8080", referrer: "https://192.168.1.105:8080/UPLOAD_URL"
Solution for PHP
Edit the php.ini file.
On the Mac, php.ini is located at /usr/local/etc/php/8.4/php.ini
.
On Debian and most Linux distros, it is located at /etc/php/8.4/fpm/php.ini
.
It may be different in yours.
Edit php.ini and look for these keys:
-
file_uploads = On
First, make sure this statement is uncommented, so file uploads are enabled. -
upload_max_filesize = 8M
Theupload_max_filesize
key sets the maximum file size for files that can be uploaded at a time. At this point, it is set to8MB
. We will change it to20M
. -
post_max_size = 8M
Thepost_max_size
key sets the file size limit to be uploaded via POST.
Your updated lines should be these:
file_uploads = On
upload_max_filesize = 20M
post_max_size = 20M
Save and exit to the command line.
Then, restart PHP-fpm.
sudo systemctl restart php8.4-fpm
If you are running it on a Mac as a Homebrew service, do this:
brew services restart php
Output:
$ brew services restart php
Stopping `php`... (might take a while)
==> Successfully stopped `php` (label: homebrew.mxcl.php)
==> Successfully started `php` (label: homebrew.mxcl.php)
Go back to the upload page and try to upload a file larger than 8MB. You should be able to upload your files successfully!
Has this worked for you?
If this tutorial has worked for you, please let me know, and share this post. You can also contact me with any questions or post in the comments below.
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.