PHP Increase Upload File Size Limit

See all PHP related FAQ
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:

    See all Apache Webserver related FAQ
  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.

There are two methods two fix this problem.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category Web Server
OS compatibility AlmaLinux Alpine Amazon Linux Arch CentOS Debian Fedora Linux macOS Mint openSUSE Pop!_OS RHEL Rocky Stream SUSE Ubuntu
Est. reading time 2 minutes

Method # 1: Edit php.ini to increase PHP upload file size limit

Edit your php.ini file (usually stored in the /etc/php.ini or /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini or /etc/php82/conf.d/99_custom.ini). For example:
# vi /etc/php.ini
Sample outputs:

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

Save and close the file. Restart the apache or lighttpd web server:
# service httpd restart
For systemd based Linux distro, type:
# systemctl restart httpd
Lighttpd Linux users, type:
# service lighttpd restart
For systemd based Linux distro type:
# systemctl restart lighttpd
Are you using the Nginx websrver with PHP-fpm? Restart the following services using the systemctl command or service command as follows:
# service nginx restart
For systemd based Linux distro:
# systemctl restart nginx
Finally restart or reload the php fpm service. For example:
# systemctl start php-fpm #RHEL/CentOS/Fedora
# systemctl start php7.0-fpm.service #Debian/Ubuntu
# /etc/init.d/php-fpm81 restart #Alpine Linux

Method #2: Edit the .htaccess file when using the Apache as web server

Edit the .htaccess file in your web server’s Document 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:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

32 comments… add one
  • 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

    • Anonymous Sep 28, 2023 @ 20:35

      Yes, 13 years later page is still useful. Thank you.

Leave a Reply

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

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.