Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

WordPress in Docker keeps the old upload size limit

ErrorUploads over 2 MB fail in the media library although you edited php.ini inside the container

Short answer

The wordpress image runs stock PHP, whose default upload limit is 2M with an 8M POST cap. Put your own ini file into the image's conf.d directory, keep post_max_size above upload_max_filesize, and rebuild. If a reverse proxy sits in front, raise its body-size limit as well; nginx stops at 1m.

  • Applies to wordpress Docker image, PHP 8.3, nginx 1.26, Docker Compose v2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP inside the running container which values it really uses. If they are still the defaults, the ini file did not reach the image.

    docker compose exec wordpress php -i | grep -E "upload_max_filesize|post_max_size|memory_limit"
  2. 2Match what you see, then jump to its fix

    1. 1The command above prints upload_max_filesize => 2M and post_max_size => 8MNo custom ini file in the image's conf.d directoryFix
    2. 2upload_max_filesize looks right, yet big files fail and $_POST and $_FILES arrive emptypost_max_size or memory_limit is smaller than the file limitFix
    3. 3413 Request Entity Too Large from nginx, before PHP sees the requestA reverse proxy in front rejects the bodyFix

What does the error look like?

  • Uploads over 2 MB fail in the media library although you edited php.ini inside the container
  • 413 Request Entity Too Large
  • Large upload returns to the form with empty $_POST and $_FILES

Cause 1 of 3

No custom ini file in the image's conf.d directory

1Check

PHP's defaults are upload_max_filesize 2M and post_max_size 8M. Edits made by hand in a running container are lost when it is recreated. The official image reads extra ini files from $PHP_INI_DIR/conf.d/.

docker compose exec wordpress bash -c 'ls $PHP_INI_DIR/conf.d/'

2Fix

Create custom.ini, copy it into conf.d in a small Dockerfile, and make Compose build that image.

# custom.ini
upload_max_filesize = 64M
post_max_size = 72M
memory_limit = 256M

# Dockerfile
FROM wordpress:latest
COPY custom.ini $PHP_INI_DIR/conf.d/

# compose.yaml (wordpress service)
build: .

3Verify

Rebuild, recreate and print the values again.

docker compose up -d --build
docker compose exec wordpress php -i | grep -E "upload_max_filesize|post_max_size"

Confirmed by hub.docker.com

Did this fix it?

Cause 2 of 3

post_max_size or memory_limit is smaller than the file limit

1Check

A file upload travels inside the POST body, so post_max_size has to be larger than upload_max_filesize, and memory_limit should be larger than post_max_size. When the POST body is too big, PHP drops $_POST and $_FILES silently.

docker compose exec wordpress php -i | grep -E "upload_max_filesize|post_max_size|memory_limit"

2Fix

Keep the order memory_limit > post_max_size > upload_max_filesize in custom.ini, rebuild, and retry.

upload_max_filesize = 64M
post_max_size = 72M
memory_limit = 256M

3Verify

The three values print in that order of size.

docker compose up -d --build

Confirmed by php.net

Did this fix it?

Cause 3 of 3

A reverse proxy in front rejects the body

1Check

nginx allows a 1m request body by default, no matter what PHP allows. If nginx proxies to the WordPress container, requests above 1 MB end with 413.

grep -rn client_max_body_size /etc/nginx/

2Fix

Set client_max_body_size in the server block that proxies to WordPress, equal to or above upload_max_filesize.

server {
    client_max_body_size 64m;
}

3Verify

Test the config, reload nginx, upload again.

sudo nginx -t && sudo systemctl reload nginx

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • Keep custom.ini in the project repository and build the image from it, so a recreated container never loses the settings.
  • Change the PHP limits and the proxy limit in the same commit.
  • Set limits to the size you actually need instead of a huge number.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.