ThisCalculator

Everyday

Fix WordPress Upload Limit Over 2MB in Nginx

Updated · Standard formula, shown below

Fix WordPress Upload Limit Over 2MB in Nginx

If your WordPress site runs on Nginx and you can’t upload files larger than 2MB, the default PHP upload limit is the culprit. This guide shows you how to raise that limit by editing the PHP configuration and, if needed, the Nginx server block. You’ll be uploading larger files in about five minutes.

What You’ll Need

  • SSH or terminal access to your server (or a file manager in your hosting control panel).
  • sudo or root privileges to edit system files.
  • Knowledge of your PHP version (run php -v or check your hosting dashboard).
  • The path to your WordPress installation (usually /var/www/html or /usr/share/nginx/html).

Step-by-Step

  1. Find your PHP configuration file. The main file is usually php.ini. Its location varies by OS and PHP version. Common paths:
    • Ubuntu/Debian with PHP-FPM: /etc/php/8.1/fpm/php.ini (replace 8.1 with your version)
    • CentOS/RHEL: /etc/php.ini or /etc/php-fpm.d/
    • If unsure, run php --ini to see the loaded file.
  2. Edit the php.ini file. Open it with a text editor, e.g., sudo nano /etc/php/8.1/fpm/php.ini. Look for these three directives (they may be commented out with a semicolon):
    • upload_max_filesize – sets the maximum file size for uploads. Change it to something like 64M.
    • post_max_size – must be larger than upload_max_filesize because it covers the entire POST request. Set it to 80M.
    • memory_limit – PHP’s memory cap; for large uploads, set it to at least 128M or 256M.

    Example changes:

    upload_max_filesize = 64M
    post_max_size = 80M
    memory_limit = 256M
  3. Save and close the file. In nano, press Ctrl+X, then Y, then Enter.
  4. Restart PHP-FPM. The service name depends on your setup. Common commands:
    • Ubuntu/Debian: sudo systemctl restart php8.1-fpm (adjust version)
    • CentOS/RHEL: sudo systemctl restart php-fpm
  5. Check Nginx’s client_max_body_size. Nginx has its own limit that can block uploads before PHP even sees them. Open your Nginx configuration file (usually in /etc/nginx/sites-available/ or /etc/nginx/conf.d/). Add or modify this line inside the server block:
    client_max_body_size 64M;

    If you have a separate location block for PHP, you can put it there too, but the server level is fine.

  6. Test Nginx configuration and reload. Run sudo nginx -t to check for syntax errors. If it says OK, reload Nginx with sudo systemctl reload nginx.
  7. Verify the change. In your WordPress admin, go to Media > Add New. The uploader should now accept files larger than 2MB. You can also create a quick PHP file in your web root with <?php phpinfo(); ?> and open it in a browser to see the current values. Delete the file afterward for security.

Common Mistakes

  • Editing the wrong php.ini. There may be multiple PHP versions or a CLI vs FPM version. Use php --ini to confirm which file is loaded for your web server.
  • Setting post_max_size smaller than upload_max_filesize. This causes uploads to fail with a “POST Content-Length exceedsâ€� error. Always set post_max_size larger.
  • Forgetting to restart PHP-FPM. Changes to php.ini only take effect after a restart.
  • Ignoring Nginx’s client_max_body_size. Even if PHP allows 64MB, Nginx will reject requests over its own limit (often 1MB by default).
  • Using a value that’s too large. Setting upload_max_filesize to 1GB on a shared server may cause memory or timeout issues. Choose a realistic limit.

Tips

  • Use a plugin to set limits without SSH. Plugins like “WP Maximum Upload File Sizeâ€� can adjust these values via the WordPress admin, but they may not work if your server blocks the ini_set function. They’re a convenient alternative for beginners.
  • Increase PHP execution time. Large uploads can take time. Set max_execution_time to 300 or higher in php.ini to avoid timeouts.
  • Keep a backup. Before editing configuration files, copy them: sudo cp /etc/php/8.1/fpm/php.ini /etc/php/8.1/fpm/php.ini.bak.
  • Test with a dummy file. Create a 5MB file with dd if=/dev/zero of=test.bin bs=1M count=5 and try uploading it to see if the limit is lifted.

Troubleshooting

  • Upload still fails after changes. Check the PHP error log (usually /var/log/php-fpm.log or /var/log/php8.1-fpm.log) for specific messages. Also verify that you edited the correct php.ini by running php -i | grep upload_max_filesize on the server.
  • Nginx returns 413 Request Entity Too Large. This means client_max_body_size is still too small. Double-check that you added the line in the correct server block and reloaded Nginx.
  • Changes not reflected in WordPress. WordPress may cache the values. Clear any caching plugins and browser cache. Also ensure you’re not using a CDN that has its own upload limits.
  • You can’t edit php.ini. On some managed hosting, you can’t access the server. Use a plugin or add a custom .user.ini file in your WordPress root (if supported) with the same directives.
  • Memory limit errors during upload. Increase memory_limit more, or reduce the upload size. Also check that max_input_time is not too low.

Frequently Asked Questions

Why is my upload limit stuck at 2MB even after editing php.ini?

Most likely you edited the wrong php.ini or didn’t restart PHP-FPM. Use php --ini to verify the path and restart the PHP service.

Do I need to change both PHP and Nginx settings?

Yes. PHP controls the file size it accepts, but Nginx has its own limit that can block the request before PHP sees it. Both must be raised.

What should I set upload_max_filesize to?

Choose a value that fits your needs. For most sites, 64MB is plenty. If you need to upload videos, consider 128MB or higher, but be mindful of server resources.

Can I set different upload limits for different users?

Yes, you can use per-directory or per-user PHP settings, but it’s complex. A simpler approach is to use a plugin that restricts upload sizes based on user roles.

Will increasing the limit slow down my site?

Not directly. Large uploads consume bandwidth and memory during the upload, but they don’t affect normal page loads. However, setting extremely high limits on a low-resource server can cause issues.

What if I use Apache instead of Nginx?

This guide is for Nginx. For Apache, you’d edit the same php.ini settings and also check LimitRequestBody in the Apache config or .htaccess.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.