Increase the maximum upload file size for WordPress

The default file upload size is 2M.

If we are supposed to increase the size, a few update would be required.

Checklist:

Update configure file php.ini

Update configure file nginx.conf

Validating our changes and restart the corresponding services

PHP.ini

Generally, php.ini is located in /etc/php.ini and defined a lot of default configurations for the php running in this server. If we can not find it, a simple grep in /etc would help.

Update this file, as follow:

; post_max_size = 8M
post_max_size = 64M
; upload_max_filesize = 2M
upload_max_filesize = 64M

post_max_size sets max size of post data allowed.

upload_max_filesize sets the maximum size of an uploaded file.

post_max_size effects the whole package of one http request, and upload_max_filesize effects the size of ONE upload file.

NGINX.conf

Since my wordpress is behind a nginx server. A simple modification of nginx is required.

client_max_body_size sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

This variable can be defined either in http {} or server {}.

I would prefer to define 64m in http {} written in /etc/nginx/nginx.conf, and override it in servers later if it is required.

http {
...
client_max_body_size 64m;
...
include /etc/nginx/conf.d/*.conf;
}

Validation and Applying

Finally, check nginx, and restart services:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ sudo service nginx restart
Redirecting to /bin/systemctl restart nginx.service
$ sudo php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service