Rewaant LLC

Infrastructure

How to increase PHP upload limit (Apache)

A brief how-to for increasing upload limit for you PHP application served by an Apache host.

R

By Rewaant ChhabraPublished December 19, 2022 · 3 min read

Title card reading Increase PHP upload limit on Apache.

Summary

A brief how-to for increasing upload limit for you PHP application served by an Apache host.

Article

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
php.ini with upload_max_filesize set to 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.
php.ini with post_max_size set to 128M.
  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.
phpMyAdmin showing an upload limit of 128M.

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.

R

About the author

Rewaant is a founder-led engineering company working across ecommerce, software and infrastructure.

About Rewaant

Let's work together

Have a related project?

Let's discuss your requirements and how we can help.

Start a Project