Increasing Apache + PHP Limits and Timeouts

Posted: 2013-10-31 20:16:23

Apache, PHP, and phpMyAdmin have multiple configuration settings that set (and limit):

These instructions will work for both Apache on Linux and for all WAMP-servers (Apache on Windows). But all the directory and file paths used here are specific to WampDeveloper Pro (…just substitute in the paths of your environment).

Increasing File Upload Limits

For uploading large files there are Apache and PHP memory limits and timeout values set that you might need to update…


Open and edit file php.ini – C:\WampDeveloper\Config\Php\php.ini

These two settings define the maximum file upload size:

upload_max_filesize = 256M
post_max_size = 257M

This will increase upload limits on a single file to 256 MB, from the default of 2 MB.

post_max_size” is set 1 MB larger than “upload_max_filesize” to take into account for any additional meta-data about the file that is included in the request (e.g., Header data).

If multiple files are uploads in the same POST request, then post_max_size will need to be set greater than the size of all the files combined (i.e., post_max_size > upload_max_filesize * number-of-files + 1MB * number-of-files).

Related PHP Settings

1. file_uploads

file_uploads = On

“file_uploads” has to be on. And usually is by default under most WAMP and LAMP setups.

2. memory_limit

memory_limit = 258M

While the PHP docs state that “memory_limit” should generally be set higher than the “post_max_size” value, is not absolutely required to be so, because file uploads are not stored/output *in their entirety* to memory. Instead, they are buffered part-by-part and written out to a file in the temporary directory (C:\WampDeveloper\Temp\) as the upload progresses.

This setting does not usually affect or limit uploads (nor downloads).

3. upload_tmp_dir

upload_tmp_dir = "C:/WampDeveloper/Temp"

This is the directory where file uploads are temporarily placed. It has to exist, and has to not have special/restrictive permissions set on it. Also there must be enough free disk space on this partition, and no overly restrictive space quotas set on this directory.

If you are using your own coded scripts to do file uploads, note that the file will be deleted from the temporary directory automatically by PHP at the end of the request. Before the script exits, you must move or copy away the file.

4. max_input_time and max_execution_time

max_input_time = 300

“max_input_time” is the amount of time a PHP script can spend “parsing” input data. The default is 60 seconds. Also, this (input “parsing” time) does not count towards the “max_execution_time” limit.

max_execution_time = 300

“max_execution_time” has no effect on upload time limits (i.e., you don’t need to modify “max_execution_time” for file uploads).

Important – these settings are limits on the possible “processing” time of the data, and not on the actual upload time itself (i.e., client upload time does not count towards max_input_time and max_execution_time).

5. max_file_uploads

max_file_uploads = 20

“max_file_uploads” sets the maximum number of files (default is 20) that can be uploaded by a single POST request (via form submit). If you are uploading more than 1 file at a time, you’ll also have to set “post_max_size” to a greater value than “upload_max_filesize” times “max_file_uploads”.


When using PHP-FCGI (a separate PHP process ran via Apache’s mod_fcgid), mod_fcgid caps uploads to 128KB by default in newer versions (v2.3.6 and above), and usually returns a “500 Server Error” when that limit is reached.

Edit file C:\WampDeveloper\Config\Apache\extra\wampd-php5-fcgi.conf

Inside the <IfModule fcgid_module> block, add in or edit setting:
FcgidMaxRequestLen 268435456

This will set the max upload value to 256 MB. Or for a 1GB (1024MB) upload limit, use value: 1073741824.

You should probably set this to match whatever max upload value you have in php.ini – though it does not have to be so.

Also for uploading and downloading files, this timeout needs to reflect the time it takes to upload/download the file:
FcgidBusyTimeout 300


Apache sets by default LimitRequestBody to 0 (specifying an unlimited size limit on the request).

This value can be overridden in any .htaccess file to another value.

Increasing Execution Timeout Limits

For processing requests there are Apache and PHP timeout values set that you might need to update (the default timeout is usually set to 300 seconds / 5 minutes)…

Apache Wait Time for Input/Output

Edit file C:\WampDeveloper\Config\Apache\extra\httpd-default.conf
Timeout 300

PHP Script Processing & Runtime Limits

Edit file C:\WampDeveloper\Config\Php\php.ini
max_execution_time = 300

PHP FastCGI Processing Timeout

When running PHP-FCGI, the FastCGI configuration sets a value on the time a FastCGI application has to respond to the I/O request (default is 40 seconds)…

Edit file C:\WampDeveloper\Config\Apache\extra\wampd-php5-fcgi.conf
FcgidIOTimeout 300

Also for busy scripts, this timeout needs to reflect the time it takes those scripts to finish:
FcgidBusyTimeout 300

Increasing PHP Memory Limits

PHP has a limit set on the amount of memory a PHP script is allowed to allocate.
memory_limit = 258M

Generally you don’t want to set a value above 2000MB (slightly lower than 2GB / 2048MB) as it 1) begins to exhaust the memory space PHP can use running as a 32 bit process and 2) has been known to trigger PHP bugs. Though normally it shouldn’t need to be higher than 1024MB as anything above is usually indicative of bad memory management or memory leakage by the PHP script used.

.htaccess and PHP code that overrides php.ini settings

If you are experiencing an Apache or PHP error message:

Out of memory (allocated X) (tried to allocate Y bytes)

Try using Notepad++ (which has a nice Find-in-files search feature), or your own choice of an Editor, to search your website’s DocumentRoot (\webroot) folder:

…For all files; And for all occurrences of this text/string:

…To see if “memory_limit” is being set in any .htaccess files (via directive: “php_value”) or PHP files (via function: “ini_set()”). Then manually edit or comment out those lines.

A) An .htaccess file could override php.ini’s memory_limit:
php_value memory_limit 20MB

B) A PHP script could override php.ini’s memory_limit:

Also note that the website’s VirtualHost file can set a value that is not overridable via .htaccess files nor script code by using the “php_admin_value” directive:
php_admin_value memory_limit 258MB

Increasing phpMyAdmin Limits

phpMyAdmin has a default limit of 300 seconds set on the import and export of dump (SQL) files. This setting does not affect the run time of any other phpMyAdmin functions.

Edit file C:\WampDeveloper\Tools\phpMyAdmin\
$cfg['ExecTimeLimit'] = 300;

phpMyAdmin also has a $cfg[‘MemoryLimit’] setting that limits the amount of memory a script can allocate for importing and exporting SQL files (and on some other internal functions), but its default value is already set with no limit:
$cfg['MemoryLimit'] = '0';

*If you do set this value for some reason (instead of letting PHP handle this limit), to specify megabytes, append an “M” to the value.