Maximum upload size in PHP and Apache?

Maximum upload size in PHP and Apache?

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

Stefan Bogdanescu

Founder & Senior Architect

Maximum upload size in PHP and Apache?

Determining whether your application can handle a file larger than 2GB requires looking beyond a single configuration value. The "maximum upload size" is not a monolithic setting locked into one place; it is a chain of constraints where the entire system must agree to proceed. If any single link in that chain breaks, the upload will fail, regardless of how generous the other settings appear.

The most common misconception is that php.ini controls everything. While PHP sets the logic for parsing and processing the file, Apache acts as the gatekeeper before PHP even sees the request. To successfully upload a multi-gigabyte file, you must audit both layers independently.

The PHP Constraints

In modern PHP installations (version 7.4 and later), the default maximum file size has been significantly reduced to 2MB. This is often set via post_max_size and upload_max_filesize. If your application relies on the standard configuration, a 2GB file will be rejected immediately with a generic error like "The uploaded file exceeds the upload_max_filesize directive."

To support larger files, you must modify these directives in your php.ini or environment-specific configuration files (such as .env for Laravel). However, there is a critical hierarchy: post_max_size must always be strictly greater than upload_max_filesize. If you set upload_max_filesize to 3GB but leave post_max_size at the default 8MB, the upload will fail because the POST body itself exceeds the limit before PHP even attempts to parse the file.

; In php.ini or environment variables
upload_max_filesize = 3G
post_max_size = 4G
memory_limit = 4G

Note that memory_limit also plays a role here. When PHP processes an uploaded file in memory, it cannot exceed this limit. For massive files, you might need to increase this value to match your new upload limits, though handling such large payloads often requires careful stream processing rather than loading the entire file into RAM.

The Apache Bottleneck

Even if PHP is perfectly configured, Apache can still block the request based on LimitRequestBody. This directive resides in httpd.conf or a virtual host configuration file (like /etc/apache2/sites-available/your-site.conf). By default, many distributions set this to 8MB. If you attempt to upload a 3GB file without adjusting this, Apache will drop the connection with an HTTP 413 Payload Too Large error before the request ever reaches PHP.

To lift this restriction, locate your Apache configuration and add or modify the directive:

<IfModule mod_authz_core.c>
    LimitRequestBody 0
</IfModule>

Setting LimitRequestBody to 0 effectively removes the limit in Apache 2.4+. In older versions (Apache 2.2), you might need to set it to a specific high integer, such as -1, or simply ensure no limit is active. Be aware that removing this limit entirely can expose your server to Denial of Service (DoS) attacks if an attacker sends a request with a massive Content-Length header but little actual data.

Trade-offs and Security Considerations

Increasing these limits is operationally safe only if you understand the resource implications. A 3GB file upload consumes significant disk space on the server during the write process. If your web server runs out of inodes or disk space, the upload will fail mid-stream, potentially leaving corrupted partial files.

Furthermore, handling multi-gigabyte uploads via standard $_FILES arrays in PHP can be risky. Loading a 3GB file into memory is generally bad practice. You should implement stream-based processing to handle the file as it arrives on disk. This approach prevents memory exhaustion and allows for better error handling if the upload is interrupted.

Conclusion

If you need to handle files larger than 2GB, do not assume PHP or Apache will negotiate this automatically. You must explicitly configure upload_max_filesize, post_max_size, and memory_limit in PHP, while ensuring LimitRequestBody in Apache is raised accordingly. For complex needs where these configurations are difficult to manage manually, platforms like https://laravelcompany.com offer hosting solutions that pre-configure these limits for large-scale applications. Always test your configuration with a file slightly under the new limit before deploying to production to catch edge cases early.

Our network