How to Increase File Upload Size In Apache Config

How to Increase File Upload Size In Apache Config

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

Stefan Bogdanescu

Founder & Senior Architect

How to Increase File Upload Size In Apache Config

Increasing file upload limits in an Apache environment often feels like a game of whack-a-mole. You tweak one setting, and the client-side error vanishes only to be replaced by a server-side rejection. This specific friction is particularly common when deploying Laravel applications, where the framework's default MAX_FILE_SIZE logic interacts with Apache's own request body limits.

The core issue usually stems from a misunderstanding of where the limit is actually enforced. When you attempt to upload a file larger than 5MB and encounter that error, it is rarely just PHP's configuration (php.ini) that is at fault; it is almost always Apache's LimitRequestBody directive acting as the hard gatekeeper. If this value is set too low in your virtual host or .htaccess file, Apache will reject the request before PHP ever gets a chance to process it.

The LimitRequestBody Directive

The configuration snippet you encountered attempts to solve this by setting LimitRequestBody 67108864. This value corresponds to 64 megabytes (1 byte = 8 bits). While this successfully raises the limit for the specific directory where it is applied, placing this directive inside an .htaccess file carries significant caveats.

The .htaccess file resides in a directory that must be served by Apache and processed via mod_rewrite. Crucially, directives like LimitRequestBody are not always available in .htaccess. This availability depends entirely on the AllowOverride directive within your main Apache virtual host configuration (often found in /etc/apache2/sites-available/000-default.conf or similar files).

If your AllowOverride is set to None, Deny, or if the server version does not permit LimitRequestBody overrides at the directory level, this line will be silently ignored. Apache will revert to its default limit, which is often 2MB or 8MB depending on the distribution. This explains why changing the value in .htaccess might appear to work for small files but fail immediately once you exceed the server's default threshold.

Correct Implementation Strategy

To reliably increase the upload size, you have two primary paths: modifying the global virtual host configuration or ensuring your .htaccess is actually permitted to override these settings.

Option 1: Virtual Host Configuration (Recommended)

The most robust solution is to apply the LimitRequestBody directive in the main virtual host configuration file. This ensures the limit applies globally to that domain, bypassing the permissions issues associated with .htaccess.

  1. Locate your site configuration, typically at /etc/apache2/sites-available/00-default.conf or /etc/httpd/conf.d/vhost.conf.
  2. Add or modify the LimitRequestBody directive inside the <VirtualHost> block:
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html
    
    # Increase limit to 64MB (67108864 bytes)
    LimitRequestBody 67108864

    <Directory "/var/www/html">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

After making these changes, you must restart Apache for them to take effect:

sudo systemctl reload apache2
# or
sudo systemctl restart httpd

Option 2: Validating .htaccess Overrides

If you strictly require the configuration to live in .htaccess, you must verify that your AllowOverride setting permits it. Look for the following in your main config file and ensure AllowOverride is set to All or at least Limit:

<Directory "/var/www/html">
    AllowOverride All
</Directory>

Once confirmed, your .htaccess file can contain the LimitRequestBody directive within a <Directory> block, exactly as shown in your source examples. However, be aware that this approach is slightly less performant than global configuration because Apache must check every request against the directory context.

Don't Forget PHP Configuration

Adjusting Apache's LimitRequestBody only removes the network-level barrier. If your application still refuses large files, you must also increase PHP's internal limits. In a Laravel environment, this involves editing php.ini or adding lines to the .env file if running via PHP-FPM.

Ensure these values are raised appropriately:

  • upload_max_filesize: Set to match your new Apache limit (e.g., 64M).
  • post_max_size: Must be larger than upload_max_filesize. If this is lower, POST requests will fail regardless of the file size.

Summary of Trade-offs

Raising these limits introduces security considerations. By allowing 64MB uploads, you are accepting that your server can accept and process significantly more data per request. This increases memory consumption during the upload process and expands your attack surface if user-uploaded content is not rigorously sanitized. Always ensure that file type validation occurs in code, not just by relying on file extensions or MIME types provided by the client.

Our network