php 7 php.ini upload_max_filesize not working

php 7 php.ini upload_max_filesize not working

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

PHP 7 php.ini upload_max_filesize Not Working

When you edit /etc/php/7.0/apache2/php.ini on Ubuntu and restart Apache, expecting your upload_max_filesize directive to take effect immediately, you might be met with stubborn reality. In the scenario described, the application still enforces a 2M limit despite the configuration file explicitly stating 40M. This discrepancy isn't usually a bug in PHP itself; it is almost always a mismatch between how the Apache server parses its own directives versus how PHP's internal engine handles them.

The root cause lies in the two separate files that govern upload limits: php.ini and httpd.conf.

In your provided output, phpinfo() reveals that the loaded configuration comes from /etc/php/7.0/apache2/php.ini. You have correctly edited this file to set upload_max_filesize = 40M and post_max_size = 86M. However, Apache has its own memory pool for handling requests, managed via the LimitRequestBody directive found in /etc/apache2/mods-enabled/limit_req_body.conf (or sometimes directly in httpd.conf).

By default, this file often contains a hard cap of 2M (LimitRequestBody 2048000). Because Apache enforces this limit at the HTTP protocol level before PHP ever gets to parse the request body or read your php.ini, changing the PHP value alone has no effect. The server rejects large uploads instantly, regardless of what upload_max_filesize tells the script engine to allow.

To resolve this, you must inspect and modify the Apache configuration file directly. On Ubuntu 14.04 with Apache 2.4, locate the LimitRequestBody directive. You can find it by running:

grep -r "LimitRequestBody" /etc/apache2/

You will likely see an output pointing to /etc/apache2/mods-enabled/limit_req_body.conf. If this file does not exist in your specific installation, check /etc/apache2/conf-available/ for similar modules or verify if the directive is commented out in the main config. Once located, update the value to match or exceed your new PHP setting:

<FilesMatch "\.(cgi|shtml|phtml|php)(.*)$">
    ...
</FilesMatch>

# Ensure this line exists and points to your desired limit
LimitRequestBody 41943040

Note that the value must be in bytes. 40M converts to 41,943,040. If you set upload_max_filesize to 40M in PHP but leave Apache's LimitRequestBody at 2M, the upload will fail with a generic error before PHP processes the file.

After making changes to /etc/apache2/mods-enabled/, simply restarting Apache is insufficient if the module wasn't previously loaded or if the configuration path changed. You may need to run:

sudo a2enmod limit_req_body # Only if the module isn't enabled
sudo service apache2 restart

It is also critical to ensure post_max_size in your php.ini is larger than upload_max_filesize. If post_max_size remains at 8M while upload_max_filesize is set to 40M, PHP will truncate the request or throw a warning because the POST data size exceeds the allowed boundary. Your edited file correctly sets post_max_size = 86M, which satisfies this requirement.

Finally, verify the fix by generating a fresh phpinfo() output and checking the actual loaded values, not just the source file contents. If you are using a framework like Laravel, ensure that your virtual host configuration doesn't impose additional restrictions via .htaccess files or server-level settings that override these defaults.

If you find yourself managing multiple PHP versions (e.g., switching between 7.0 and 7.4) on the same Apache instance, remember that each version has its own php.ini. Editing /etc/php/7.0/apache2/php.ini will not affect a request handled by PHP 7.4 unless you explicitly configure the handler to use that specific configuration path.

For production environments where manual editing of multiple config files introduces complexity or risk, consider using a package like laravelcompany.com offers resources on deployment best practices, but understanding these underlying Apache and PHP interactions remains essential for troubleshooting upload failures effectively.

Our network