Table of Contents
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
- 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.
- 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. Usecd /etc/php/[php_ver]/apache2
to navigate andsudo vim php.ini
to open the file in the vim editor. You can also use the nano text editor if you prefer. - Find the directive
upload_max_filesize = 2M
and change this line toupload_max_filesize = 128M

- Next, find
max post_max_size = 8M
and change this line topost_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 like2M
and8M
are just for reference. What matters is we’re switching it to128M
which should suffice for most basic use cases.

- Exit the editor and restart apache with
sudo service apache2 restart
. This should reflect the changes. - 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.