TechBuzzPro

Increase PHP Maximum Upload Size

· 6 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

If you've ever tried to upload a large file through a PHP-based website or application and hit an error like "The uploaded file exceeds the upload_max_filesize directive," you're dealing with PHP's built-in upload limits. By default, PHP allows uploads of only 2 MB, which is far too small for videos, high-resolution images, or large PDFs. This guide walks you through the exact steps to increase that limit by editing your PHP configuration files. You'll need access to your server's file system and the ability to edit configuration files—if you're on shared hosting, you may be limited to using the cPanel file manager or a custom php.ini file.

What You'll Need

  • Access to your server's file system (via FTP, SSH, or a hosting control panel like cPanel or Plesk).
  • Ability to edit files like php.ini, .htaccess, or .user.ini.
  • Knowledge of where your PHP configuration file is located (use phpinfo() to find it).
  • A text editor (Notepad++, VS Code, or even the built-in editor in cPanel).

Step-by-Step

  1. Find your current PHP configuration. Create a file named phpinfo.php with the content <?php phpinfo(); ?>, upload it to your web root, and open it in a browser. Look for the Loaded Configuration File line—that's the path to your main php.ini file. Also note the current values of upload_max_filesize and post_max_size.
  2. Decide which configuration method to use. If you have root or administrator access, edit the main php.ini file. If you're on shared hosting, you may need to use a .htaccess file (for Apache) or a .user.ini file (for CGI/FastCGI). Choose the one that applies to your server setup.
  3. Edit php.ini (if you have access). Open the php.ini file in a text editor. Locate the lines for upload_max_filesize and post_max_size. Change them to your desired values, e.g., upload_max_filesize = 100M and post_max_size = 100M. Also check max_execution_time and max_input_time—increase them to, say, 300 seconds each if you're uploading large files. Save the file.
  4. Edit .htaccess (if you're on Apache and can't edit php.ini). In your web root or the directory where the upload script resides, open or create a .htaccess file. Add these lines: php_value upload_max_filesize 100M and php_value post_max_size 100M. You can also set php_value max_execution_time 300 and php_value max_input_time 300. Save the file.
  5. Edit .user.ini (for CGI/FastCGI). If your server uses PHP-FPM, you can create a .user.ini file in your public_html directory with the same directives: upload_max_filesize=100M and post_max_size=100M. This file is often used on shared hosting.
  6. Restart the web server or PHP-FPM. If you edited php.ini, you must restart Apache or Nginx (and PHP-FPM if used) for changes to take effect. On shared hosting, you may not be able to restart—in that case, changes to .htaccess or .user.ini usually apply immediately, but some hosts require a short wait.
  7. Verify the change. Re-open the phpinfo.php file in your browser and check the upload_max_filesize and post_max_size values. If they show your new values, you're done. Delete the phpinfo.php file for security.

Common Mistakes

  • Only changing upload_max_filesize. The post_max_size must be equal to or larger than upload_max_filesize because the file is sent as part of the POST request. If post_max_size is smaller, your upload will still fail.
  • Using the wrong file. Editing php.ini when your server uses .htaccess or vice versa can result in no change. Always check which method your host supports.
  • Forgetting to restart the server. Changes to php.ini won't take effect until the web server or PHP-FPM is restarted. Some hosts require you to do this through a control panel.
  • Setting values too high. Setting upload limits to 1 GB on a shared server can cause memory issues or be overridden by the host. Also, your server's client_max_body_size (Nginx) or LimitRequestBody (Apache) can override PHP settings.
  • Ignoring memory limits. PHP's memory_limit must be at least as high as post_max_size for the script to handle the upload. Set it to, e.g., 128M or higher.

Tips

  • Use consistent values. A common practice is to set upload_max_filesize and post_max_size to the same value, and memory_limit to twice that value.
  • Check your web server limits. If you're using Nginx, look for client_max_body_size in the server block and increase it. For Apache, check LimitRequestBody in the configuration.
  • Test with a dummy file. After making changes, upload a file of the maximum size you expect to handle to confirm everything works.
  • Keep a backup. Before editing php.ini or .htaccess, save a copy so you can revert if something breaks.

Troubleshooting

If the new limits don't take effect, try these checks in order:

  1. Confirm you're editing the correct file. Re-run phpinfo() and look at the Loaded Configuration File path. If you edited a different php.ini, your changes won't apply.
  2. Check for overrides. Some hosting providers set their own limits in a parent configuration file that overrides yours. Look for php_admin_value directives in Apache config or php_admin_flag in FPM pools—these cannot be overridden by .htaccess or .user.ini.
  3. Verify syntax. A typo in php.ini can cause the server to ignore the file. Use php -l /path/to/php.ini from the command line to check syntax.
  4. Restart everything. If you're using PHP-FPM, restart both FPM and the web server. On some systems, you need to run sudo systemctl restart php-fpm apache2 (or nginx).
  5. Look for other limits. If you're still getting errors, check the server error logs. The error may be from the web server (e.g., Nginx's client_max_body_size) rather than PHP.
  6. Ask your host. If you've tried everything and it still doesn't work, contact your hosting provider. They may have restrictions in place that you can't bypass.

Frequently Asked Questions

1. What is the default PHP upload limit?

By default, PHP sets upload_max_filesize to 2 MB and post_max_size to 8 MB. These values can be lower on some hosts.

2. Do I need to change both upload_max_filesize and post_max_size?

Yes. The file is sent as part of a POST request, so post_max_size must be at least as large as upload_max_filesize. If you only increase the upload limit, the POST size limit will still block larger files.

3. Can I increase the limit using only a PHP script?

No. You cannot change these directives at runtime using ini_set() because they are PHP_INI_PERDIR settings, which means they must be set in php.ini, .htaccess, or .user.ini before the script runs.

4. Why does my upload still fail after I increased the limit?

Other factors can interfere: the web server's own request size limit (e.g., Nginx's client_max_body_size), the memory_limit in PHP, or the script's execution time. Check all of these.

5. Is it safe to set the upload limit to 1 GB?

It's possible, but it depends on your server's resources. Large uploads consume memory and disk space. On shared hosting, the host may override your settings or reject such high values. It's safer to set a limit that matches your actual needs.

6. How do I find the correct php.ini file?

Create a file with <?php phpinfo(); ?> and open it in a browser. Look for the "Loaded Configuration File" entry—that's the file you need to edit. Delete the file afterward.