Increase file upload size in WordPress on Nginx server
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.iniLocate and change these settings:
post_max_size = 128M
upload_max_filesize = 128MSave and exit Vim by typing :wq (Write and quit.)
Finish by restarting PHP-FPM:
$ sudo service php7.0-fpm restartThen have a beer. Good work! 🍻
