Increasing Apache + PHP Limits and Timeouts

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

  • Memory Usage (Allocation)
  • PHP Script Run Times
  • Upload File Sizes

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.

9 thoughts on “Increasing Apache + PHP Limits and Timeouts”

  1. There is a lot of confusion on the net and the PHP docs about setting memory_limit in relation to upload_max_filesize and post_max_size.

    Here is the sourcecode to the PHP rfc1867_post_handler / function…;a=blob;f=main/rfc1867.c;hb=refs/heads/PHP-5.3

    I can’t really tell if it’s buffering parts, writing them out to disk, then recycling the buffer; or outputing the whole thing to memory (or has a bug in it that does so anyways).

    On another note here are the listed error messages –

     132 /* Errors */
     133 #define UPLOAD_ERROR_OK   0  /* File upload succesful */
     134 #define UPLOAD_ERROR_A    1  /* Uploaded file exceeded upload_max_filesize */
     135 #define UPLOAD_ERROR_B    2  /* Uploaded file exceeded MAX_FILE_SIZE */
     136 #define UPLOAD_ERROR_C    3  /* Partially uploaded */
     137 #define UPLOAD_ERROR_D    4  /* No file uploaded */
     138 #define UPLOAD_ERROR_E    6  /* Missing /tmp or similar directory */
     139 #define UPLOAD_ERROR_F    7  /* Failed to write file to disk */
     140 #define UPLOAD_ERROR_X    8  /* File upload stopped by extension */
  2. If you are finding yourself getting logged out (for example – out of phpmyadmin), you might be hitting a sessions limit…

    If php.ini is set to store sessions in filesystem (default behavior):
    session.save_handler = files

    PHP will clean up (remove) that session data if the modification time for the session file has not changed for 1440 seconds (24 minutes):
    session.gc_maxlifetime = 1440

    And you might get logged out.

    This value can be set in php.ini, htaccess files (php_value), and in code (ini_set()).

    Note –
    1. Do not use subdirectories for sessions in php.ini (session.save_path = “N;/path”) as this will break automatic garbage collection.

    2. The default behavior for session cookie lifetime is to not expire until the Browser is restarted…
    session.cookie_lifetime = 0

  3. Generally speaking, it’s not a good idea to attempt to upload files larger than 2GB via Apache and PHP, due to inherent limits and 32/64 bit integer bugs in the codebases.

    The stateless HTTP protocol was also never ment to handle these types of large file uploads.

    Use FTP, or some other mechanism, to upload files larger than 2GB.

  4. MySQL Server has gone Away

    php.ini defines the amount of time PHP will wait for a connection to MySQL to establish and/or the amount of time to wait between responses to/from the database before dropping the connection.

    mysql.connect_timeout 60
    default_socket_timeout 60

    If your PHP scripts do not close connections properly, or the server is very active (has many connections), setting these value higher will cause overload issues – with too many PHP threads waiting needlessly.

    The only time you should set these values higher is when you have a very long running PHP script doing work while never pinging back MySQL (a script that establishes a connection, does a bunch of work, and then uses that connection at the end).

  5. If anyone struggles with the Apache Wait Time, I believe there is a small typo in the instructions:
    Timeout = 300
    should be
    TimeOut 300
    Otherwise your Apache service will not restart.

  6. I cannot upload files larger than 150MB to my personal server or a godaddy server. I believe there is a http limit or apache limit holding me back. I have set all of my settings very high to test but nothing is working.


    register_globals = off
    allow_url_fopen = off
    max_file_uploads = 200
    max_input_time = 3600
    max_execution_time = 3600
    max_input_vars = 2000
    memory_limit = 1024M
    upload_max_filesize = 1024M
    post_max_size = 1024M
    expose_php = Off
    variables_order = "EGPCS"
    extension_dir = ./
    upload_tmp_dir = /tmp
    1. Have you checked the Apache and PHP error log files? If the problem is with Apache or PHP, the error logs will explain what the issue is.

      Is file_uploads = On?

      Have you checked all the .htaccess files for overriding settings?

      Are you moving the randomly named uploaded file out of /tmp and into its proper path and name before the script ends/terminates? As when this happens the uploaded file will get deleted.

  7. Hello,

    I am using Worpdress and I need to run a special script temporally, so I need to increase the max_execution_time

    I did it in the website files php.ini but nothing changes.
    Does it mean that I have to do in on the server directly ?

    I read that I need to edit the setting listed as
    FcgidIOTimeout 120
    httpd.conf file

    Can you confirm and tell me what commands to use to do this ?

    Thank you so much for your help.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>