How to Increase the File Upload Size using .htaccess file

How to Increase the File Upload Size using htaccess file

Apache is one of the most popular web servers in the world. However, it has a default file upload size that might limit user’s ability to upload large files and media to your website. However, you can easily solve this problem by modifying a couple of lines in your .htaccess file on apache. Here’s how to increase the file upload size using .htaccess file.


Before you begin, please ensure that mod_rewrite is enabled on your Apache installation. If you have not enabled .htaccess (or mod_rewrite) on your Apache server, you can do it by following the steps mentioned below:

  1. How to Enable mod_rewrite for Apache in Ubuntu
  2. How to Enable mod_rewrite for Apache in CentOS


How to Increase the File Upload Size using .htaccess file

Step 1. Open the .htaccess file using a test editor and add the following line of code:

php_value upload_max_filesize xxM

Here xx is the max upload file size you want in megabytes. So if you want the max size to be 64Mb, then paste the following command:

php_value upload_max_filesize 64M


Step 2. Add the following line to increase the maximum HTTP POST file size. Replace xx with the file size, in megabytes, as per your requirement.

php_value post_max_size xxM


Please ensure that post_max_size is slightly bigger than upload_max_filesize. For example, if your upload_max_filesize is 20MB then post_max_size should be 21MB.


Step 3. Save the changes to .htaccess file, exit and the test editor. Restart your apache server with the command:

For Ubuntu (debian-based Linux)

$ sudo service apache2 restart

For CentOS (rpm-based linux)

$ sudo systemctl restart httpd


Step 4. Test it by creating a simple PHP file (info.php) in the same directory as .htaccess file and add the following code to it.

<?php phpinfo(); ?>

Load it in your browser and search for the directives, namely upload_max_filesize and post_max_size. The Local Value will show you their values.


If you are using a shared hosting account, then the above method might not work. In that case, it’s best to contact your web hosting provider and request to them to increase the limit.

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!