How to Increase PHP post_max_size for Large File Uploads

This guide explains what the PHP post_max_size directive does, why the default 8M limit often fails for large uploads, and provides step‑by‑step methods—including editing php.ini, using .htaccess, and runtime ini_set—to correctly configure post_max_size along with related settings such as upload_max_filesize, memory_limit, and max_execution_time.

php Courses
php Courses
php Courses
How to Increase PHP post_max_size for Large File Uploads

What is post_max_size?

post_max_size is a PHP configuration directive in php.ini that defines the maximum size of data that can be submitted via POST, including all form fields and uploaded files. Its default is often 8M, which is insufficient for large uploads.

How to set post_max_size

There are three common methods, depending on server access:

Modify php.ini (recommended for own server/VPS)

Locate php.ini (use a <?php phpinfo(); ?> script to find the "Loaded Configuration File" path).

Edit php.ini with a text editor and search for post_max_size.

Change the value, e.g. post_max_size = 64M or post_max_size = 1G.

Save and restart the web server:

Apache: sudo systemctl restart apache2 Nginx + PHP‑FPM: sudo systemctl restart nginx php8.1-fpm Use .htaccess (Apache shared hosting)

Create or edit a .htaccess file in the site root.

Add the following line: php_value post_max_size 100M Save; changes take effect without a server restart if the Apache configuration permits.

Runtime ini_set() (limited)

<?php
ini_set('post_max_size', '50M');
?>

This often has no effect because PHP reads the limit before the script runs, so it is not recommended.

Important related settings

upload_max_filesize

limits the size of a single uploaded file. post_max_size must be larger than upload_max_filesize. For a 50M file, set upload_max_filesize = 50M and post_max_size to at least 55M‑60M.

Common misconfiguration example:

upload_max_filesize = 100M
post_max_size = 50M

Even an 80M file will fail because the POST request exceeds the 50M limit.

Correct configuration example:

; allow single file up to 100M
upload_max_filesize = 100M
; allow whole POST request up to 110M
post_max_size = 110M

Diagnosing upload failures

Check $_POST and $_FILES. If they are empty, the request likely exceeded post_max_size.

Inspect $_SERVER['REQUEST_METHOD']. If it became GET, the POST size was too large.

Run a phpinfo() script to verify current values of post_max_size and upload_max_filesize.

Review Apache or Nginx error logs for related messages.

Memory and execution time limits

memory_limit

– maximum memory a PHP script may use; may need to increase for large files. max_execution_time – maximum script execution time; large uploads may require a longer limit.

Summary

Properly setting post_max_size is essential for handling large POST requests and file uploads. Ensure post_max_size exceeds upload_max_filesize, adjust memory_limit and max_execution_time as needed, and restart the web server after editing php.ini.

backendFile UploadPHPphp-inipost_max_size
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.