How to increase PHP upload limit (Apache)

Posted by: Rewaant Chhabra |

Last updated: 

December 19, 2022
read time
to execute (approx.)

Table of Contents

  1. Overview
  2. Steps
  3. Conclusion

Overview

You’ve probably found yourself in a predicament where you have to upload a file to a PHP application like WordPress or PHPMyAdmin but the default server configuration only allows you to upload files up to 2048 Kbs or 2Mibs. In this short how-to, we’ll quickly explain how you can increase this limit. We’ll be demonstrating this on an AWS EC2 instance running Ubuntu 22.04.

Let’s cut to the chase…

Steps

  1. Connect to your server using SSH. If you don’t know how, please follow our guide on How to connect to a virtual server using SSH.
  2. Once connected, navigate to the directory containing your php.ini configuration file. This should be /etc/php/[php_ver]/apache2 which in our case is /etc/php/8.1/apache2 as this server is using PHP version 8.1. Use cd /etc/php/[php_ver]/apache2 to navigate and sudo vim php.ini to open the file in the vim editor. You can also use the nano text editor if you prefer.
  3. Find the directive upload_max_filesize = 2M and change this line to upload_max_filesize = 128M
  1. Next, find max post_max_size = 8M and change this line to post_max_size = 128M as well. Please note in some installations, these directives can have different values as per default or set by a sys admin. The initial values like 2M and 8M are just for reference. What matters is we’re switching it to 128M which should suffice for most basic use cases.
  1. Exit the editor and restart apache with sudo service apache2 restart. This should reflect the changes.
  2. Logging in to PHPMyAdmin shows us that we can indeed upload files up to 128M in size.

Conclusion

We should now have PHP applications accept files as big as 128MiB to be uploaded. Keep in mind these changes reflect in the complete server environment. If you’re running an application within some sort of virtualization like a Docker image, you need to make changes in there accordingly.

Stay tuned for our upcoming how-to’s and technical guides.

About Us

Rewaant LLC is an agency helping clients with the topics we write about. Feel free to get in touch for additional help.

Share This