How to increase the file upload size for PHP 7 on Ubuntu

- by

One of my supporters has read my book LAMP Stack for Humans, in which I’m explaining how to run a web server on your home or office network. He installed WordPress on it and everything worked out great, but the default upload limit of 2MB was not enough for him.

He followed the instructions in my book, googled around and applied every trick out there, yet none of the solutions he found worked on his system: the WordPress instance refused to upload anything larger than 2MB. This morning we had a chat and went through all these steps with two pairs of eyes:

  • tweak the php.ini file
  • define variables in wp-config.php
  • add and tweak .htaccess
  • even try a user.ini file – but nothing worked.

Then it dawned on me: the one thing I didn’t know was that Apache on Ubuntu uses PHP-FPM by default, which means the default php.ini file was not being used for this user-based approach of serving PHP files. What we needed to do was tweak the php.ini file in the fpm directory!

For PHP 7.4 on Ubuntu 2020 LTS, the default location is

  • /etc/php/7.4/fpm/php.ini

The following two values need to be tweaked:

post_max_size = 500M
upload_max_filesize = 500M

Once saved, restarting Apache is NOT enough to make these changes show up. Instead we need to restart PHP-FPM to see our changes:

sudo service php7.4-fpm restart

Thanks to Sandy on StackOverflow for the solution 😎



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site witout any pesky ads! More details here.

Add your voice!

This site uses Akismet to reduce spam. Learn how your comment data is processed.