How to increase the file upload limit in PHP on an Ubuntu server with NGINX?
I have a PHP web application deployed on an Ubuntu server using the NGINX web server. When trying to upload files larger than 10 MB, I encounter an error. How can I increase the file upload limit in PHP and configure NGINX to support larger files?
Answers
James Smith
Everything worked great.
Your tips helped a lot!
Something must not have updated when I checked, now everything works.
Jonas Becker
If issues persist:
Ensure your PHP code does not restrict the upload size. For example, in the upload form, add a hidden field MAX_FILE_SIZE:
Check client-side JavaScript for any limitations on file size.
Verify the file upload directory has the correct write permissions for PHP.
Double-check that no other configuration files impose lower file size limits. Consult the code developer if you did not write it.
James Smith
Did as you suggested, but the file won't upload...
Jonas Becker
To increase the PHP upload limit on Ubuntu with NGINX:
1. Modify php.ini settings
Open the PHP-FPM php.ini file for editing:
Replace 7.x with your PHP version and use your preferred text editor if not nano.
Locate and adjust the following parameters:
Ensure that post_max_size is not less than upload_max_filesize.
Save and close the editor (Ctrl + O, Enter, then Ctrl + X in nano).
2. Configure NGINX
Open your site’s configuration file, usually in /etc/nginx/sites-available/:
Add or modify the client_max_body_size directive with the desired value (e.g., 50M) inside the server block:
Save and close the editor.
3. Check and Restart NGINX and PHP-FPM
Verify NGINX configuration syntax:
If no errors, reload NGINX:
Restart PHP-FPM:
Replace 7.x with your PHP version.
4. Confirm Settings via phpinfo()
To verify the changes, create an info.php file in your website's root directory:
Add the following code:
Open the file in a browser at http://example.com/info.php. Check upload_max_filesize and post_max_size values to ensure they are updated.
After verification, delete info.php for security: