A little while ago I had a quick post on how to increase the file size and number of file upload limits by editing the values straight in the php.ini file. This approach works, but we need to understand the down sides it presents as well:

  1. The changes to the php.ini could easily be lost after a php upgrade. Each non minor php version upgrade will come with its own php.ini and our prior settings will be lost.
  2. The php.ini file is global. If we have multiple sites on the server using the same php version, then any settings we make in the php.ini file will affect all sites.
  3. These settings are most likely not included in any source control. Normally we would have our web application code pushed to a git repo for example, but since the php.ini file is not part of the application, but rather a part of the host environment, it normally would not be in the repository. Any subsequent checkouts of that repo will be missing these settings.

A better approach

Instead of making the changes in the base line php.ini file, we can make them in the .htaccess file off the root of each website we are interested of having those changes apply to. We do that by adding php_value in front of each php directive:

php_value upload_max_filesize 20M
php_value max_file_uploads 30
php_value post_max_size 608M
php_value memory_limit 616M
php_value max_execution_time 60
php_value max_input_time 120

Once we save that in the .htaccess file, the changes are instantaneous for that site. No need to restart Apache.

If we now display the phpinfo for that site, we will see that the local values of the above settings (local to the site) have changed as set above, while the master values have remained unchanged.

PHP – increase file size and number of uploads limits

Leave a Reply

Your email address will not be published. Required fields are marked *

*