PHP Increase Upload File Size Limit

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:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 31 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
31 comments… add one
  • Kevin Jun 18, 2010 @ 16:12


    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.

  • Sapan Jun 23, 2010 @ 8:39


    I apply your method2 and it really works now..

  • kayo Aug 2, 2010 @ 6:29

    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.

    • kayo Aug 2, 2010 @ 6:31

      I’m using these version:
      Apache/2.2.3 (CentOS)
      PHP Version 5.1.6

    • Yasar Nov 26, 2012 @ 4:22

      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.

  • yeswanth Oct 4, 2010 @ 9:46

    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?

    • JRM Mar 10, 2012 @ 17:22

      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


  • alreymark Oct 24, 2010 @ 8:14

    great thanks! really works well on my side. :)

  • Md. Ashraf Jahan Apr 4, 2011 @ 17:28

    Its showing internal server error (500) when I use .htaccess

    • artiemartin Mar 14, 2012 @ 18:07

      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 ..

      • Ash Apr 4, 2012 @ 18:36

        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.

  • shekhar Apr 28, 2011 @ 9:46

    thanx !!! it really worked…..

  • CSAdmin Nov 26, 2011 @ 0:05

    Thanks. Just needed help finding the php.ini file. Worked fine.

  • kamal Jan 12, 2012 @ 7:11

    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

  • subna Jan 14, 2012 @ 12:04

    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 :)

  • Jacob Jan 19, 2012 @ 19:31

    What do you do if you don’t have that string in your php.ini file? Can I just add it at the end?

    • 🐧 nixCraft Jan 20, 2012 @ 6:16

      Yes, you can add it at the end and reload / restart the webserver.

      • Jacob Jan 22, 2012 @ 3:20


  • collin Feb 1, 2012 @ 17:42

    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?

  • peerfly Feb 4, 2012 @ 11:20

    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.

  • Kenny Feb 10, 2012 @ 20:25

    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!

    • MerlinW Apr 14, 2012 @ 14:54

      You have no rights to write to the target directory. Modify the user rights/attributes.

  • andy Apr 29, 2012 @ 21:26

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

  • Hector Apr 30, 2012 @ 17:44

    Very good article, was usefully… Thank you so much.

  • Fernando Sep 17, 2012 @ 5:11

    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


  • adeniyi Mar 28, 2013 @ 21:08

    thanks am very gratefull

  • George Jul 4, 2013 @ 20:47

    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.


  • Marcin Sep 4, 2014 @ 12:08

    Thats very usefull, solved my issue. Thx.

  • Abhishek Pandit Jan 14, 2015 @ 9:23

    Thanks. It worked.

  • vivek Jul 15, 2015 @ 11:46

    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

  • Amandeep Chauhan Mar 14, 2016 @ 13:03

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum