Increase file upload size in WordPress on Nginx server

Stefan Ledin
Jul 28, 2017 · 1 min read

I got an (very helpful 🙄)HTTP error when trying to upload a 80-something MB file to WordPress the other day. Even though I had increased the maximum upload size to 128 MB.

So let’s check with our special friend: the error log.

$ sudo vim /var/log/nginx/error.log

Which said this:

client intended to send too large body

🤔 That’s strange, since 80-something is less than 128 mb. But after a few minutes of googling, it turned out that I could move the client_max_body_size “setting” from the location block to the server block in the Nginx vhost file.

From this:

# /etc/nginx/sites-avaliable/mysite.comserver {  listen 80;  listen [::]:80;  root /var/www/mysite;  index index.php index.html index.htm;  server name mysite.com www.mysite.com;  location / {    client_max_body_size 128m;    # …  }  # …}

To this:

# /etc/nginx/sites-avaliable/mysite.comserver {  listen 80;  listen [::]:80;  root /var/www/mysite;  index index.php index.html index.htm;  server name mysite.com www.mysite.com;  client_max_body_size 128m;  location / {    # ...  }  # ...}

Notice the difference? Don’t forget to run:
sudo service nginx reload

php.ini

In case you’re wondering, these are the things you have to change in thephp.ini file.

First, locate the correct php.ini file by running phpinfo(); Look at the Loaded configuration file column. It will say something like this: etc/php/7.0/fpm/php.ini

Run:

$ sudo vim /etc/php/7.0/fpm/php.ini

Locate and change these settings:

post_max_size = 128M
upload_max_filesize = 128M

Save and exit Vim by typing :wq (Write and quit.)

Finish by restarting PHP-FPM:

$ sudo service php7.0-fpm restart

Then have a beer. Good work! 🍻

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store