The Hidden Barrier: Why upload_max_filesize Isn't the Only Problem
You've configured your PHP settings to accept massive files, setting memory_limit to unlimited and pushing post_max_size up to 9G. Yet, when a client attempts to upload a file slightly over 2GB, you hit a hard wall immediately. The error log screams about exceeding a limit of 1073741824 bytes (roughly 1GB), which contradicts your post_max_size configuration entirely.
The culprit isn't the PHP runtime configuration you edited; it's the HTTP protocol layer sitting right in front of PHP. When a browser sends a large file, it constructs an HTTP POST request containing a Content-Length header. Before the request even reaches the web server to be parsed by PHP, the web server validates this header against its own limits.
If you are running Apache with mod_php or Nginx, both have their own configuration files that enforce a maximum size for incoming POST data. By default, Apache's LimitRequestBody directive is often set to 2MB (or sometimes left at a lower default depending on the distro), and Nginx has a client_max_body_size directive. If you haven't explicitly increased these values in your .htaccess, httpd.conf, or Nginx config, they will override any PHP settings you set in php.ini.
Consider this scenario: Your PHP php.ini tells the engine, "I can handle 5GB." However, the web server intercepts the request and says, "Stop. The Content-Length header indicates a request larger than my default limit of 2MB (or whatever your OS/web-server-default is)." The web server rejects the connection before PHP ever sees the file. This explains the specific error message regarding the 1GB limit; many older configurations or default distributions cap body sizes strictly around this threshold unless explicitly told otherwise.
To resolve this, you must edit your web server configuration to match your PHP settings. For Apache, locate the LimitRequestBody directive in your virtual host configuration or the main config file and set it to a value that matches your post_max_size. If you are using Nginx, ensure client_max_body_size is set appropriately in your nginx.conf or server block.
http {
# Match your PHP post_max_size setting here
client_max_body_size 9G;
}
Once the web server limit is cleared, you must also verify that your PHP configuration actually takes effect. Restarting the web server is essential after changing php.ini or Nginx/Apache configs, as these changes do not apply dynamically without a restart command like sudo systemctl restart apache2 or nginx.
There is another critical architectural consideration when dealing with files exceeding 2GB: memory. Even though you set memory_limit = -1, the standard PHP file upload process loads the entire file into RAM to parse the data before saving it. A 3GB file requires roughly 3GB of free RAM just for the upload process. If your server does not have this much available memory, PHP will attempt to use the swap file (or pagefile on Windows). Swapping large files back and forth between RAM and disk is incredibly slow and can cause the web server to become unresponsive during the upload, effectively timing out the request even if it doesn't crash.
For production environments handling multi-gigabyte uploads, it is often better to stream the file directly from the HTTP body to the filesystem using fopen() and a file pointer loop rather than relying on PHP's default $handle which might behave differently depending on the context, though modern PHP handles streams well. The real bottleneck usually isn't the code logic but the physical memory available to process the stream without swapping.
If you are building an application with Laravel, these limits must be configured in php.ini and potentially the web server config as described above. Laravel itself does not set these limits; it relies on the underlying environment. If you are using a managed hosting provider or a containerized environment like Docker, remember that the limits inside the container must match the host's capabilities, and sometimes the container runtime imposes its own caps regardless of what is in php.ini.
Finally, always test with a file slightly larger than your intended limit to ensure the configuration hierarchy is correct. A 2.1GB file will fail if your web server limit is 2GB, regardless of whether PHP is configured for 5GB. The error message you encountered highlights that the web server's default or inherited limit was still active, blocking the request before PHP could evaluate its own settings.