PHP Increase Upload File Size Limit

last updated in Categories ,

How do I increase upload file limit from 2MB to 10MB under Apache 2 UNIX / Linux web server?

Your php installation putting limits on upload file size. The default will restrict you to a max 2 MB upload file size. You need to set the following two configuration options:


  1. upload_max_filesize – The maximum size of an uploaded file.
  2. memory_limit – This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.
  3. post_max_size – Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size.
  4. There are two methods two fix this problem.

Method # 1: Edit php.ini

Edit your php.ini file (usually stored in /etc/php.ini or /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini):
# vi /etc/php.ini
Sample outputs:

memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M

Save and close the file. Restart apache or lighttpd web server:
# service httpd restart
# service lighttpd restart

Method #2: Edit .htaccess

Edit .htaccess file in your root directory. This is useful when you do not have access to php.ini file. In this example, /home/httpd/html is considered as root directory (you can also create .htaccess file locally and than upload it using ftp / sftp / scp client):
# vi /home/httpd/html/.htaccess
Append / modify setting as follows:

php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M

Save and close the file.

A Note About Suhosin (Optional)

This is not installed by default on many servers (latest version of Debian, Ubuntu, and FreeBSD does install Suhosin by default). Use phpinfo() to find out if suhosin enabled or not (create test.php):


If you are using Suhosin which was designed to protect your servers against a number of well known problems in PHP applications and on the other hand against potential unknown vulnerabilities within these applications or the PHP core itself. You need to edit /etc/php.d/suhosin.ini to set correct memory and upload limit. As long scripts are not running within safe_mode they are free to change the memory_limit to whatever value they want.

See also:


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

31 comment

  1. Hello,

    Referring to these comments, What is the MAX file size in PHP? For example, can I set it at

    upload_max_filesize = 200M
    post_max_size = 200M
    memory_limit = 300M

    Thank you in advance.

  2. upload_max_filesize = 15M
    memory_limit = 128M
    post_max_size = 25M
    I tried method 1 and 2 with these values but unable to upload 6mb of data file.

    1. I am using WAMP and working fine.

      Change the above three contents in both C:\wamp\bin\php\php5.2.6\php.ini and quick launch at the bottom of the desktop right click->PHP->php.ini

      Check it KAYO.

  3. we have Apache server in our office and i dont have access to .ini or htaccess file.
    cant we increase upload file size from our code itself?

    1. I have the same setup… did you get an answer… I need access to the htaccess or php.ini but I don’t have permissions

      is there are way to change it with scripts?

      please let me know


    1. i have the same issue .. i added the code to the htaccess and it didn’t work .. my host said he’ll get back to me cause he doesn’t know why either I assume or he would of fixed it ..

      1. I had this error when I created my .htaccess file using a program like dreamweaver. apparently you need to create it with work and make sure it has the correct encoding that your server uses.

  4. please let me know also ,i am also uploading large file and have done all settings correctly but not able to upload file of large size

  5. thank u so much. whole day i spend 2 find out dis error finally after visiting 2 dis site i got d solution of my error. thnx :)

  6. I tried the .htaccess and .ini methods both made my apache threads 780 MB a peice. They are normaly 25MB. What’s up with that?

  7. Thanks. I couldn’t upload my data base backup coz of this problem. Had to access the php.ini but only had to change post_max_size.

    .htaccess method didn’t work. I don’t know why.

  8. Is there some syntax or directive section that this goes in? If I put simply what you have:
    php_value upload_max_filesize 10M
    php_value post_max_size 20M
    php_value memory_limit 32M

    Then I get a 500 error. If I stick it in tags, I get no error, but it doesn’t work. That’s probably because, in spite of all the postings, there’s no such Apache module as mod_php. So I don’t know what to do.
    Any ideas? Thanks!

  9. All of these responses are inanely pathetic.
    They all say yes i fixed it but no one says how.
    Another waste of the internet

  10. Hi guys,

    Can you help me to configure this on my .htaccess ? My application is telling me this:

    Upload stream is blocked by Suhosin, please add “upload” to suhosin.executor.include.whitelist


  11. This solution works. However, when I set the memory limit to 32MB, it causes my CSM (Drupal 7) to fail on certain pages (like module install/uninstall, adding content, etc.). Rather than trial and error, I just added the two lines to my main .htaccess:

    php_value upload_max_filesize 10M
    php_value post_max_size 20M

    This was sufficient to increase the file upload size to 10MB.


  12. I have same issue setting done in php.ini but its not working how can I find.htaccess server having 3.5GB of memory need to increase memory as well I can upload upload upto 8MB file but not more than 8MB please guide I am new in Linux

  13. Thank You very much for your help.
    I tried second method and it really worked for me.
    ThankYou ThankYou ThankYou ThankYou ThankYou

    Still, have a question? Get help on our forum!