basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Who owns WordPress files in Docker: www-data and uid 33

    WordPress files belong to whoever runs PHP in the container: www-data, uid 33 in Debian-based images and 82 in -alpine. Hand the mounted directory to that user with one chown — on the host the number matters, not the name.

    Why the owner is www-data

    PHP writes the site’s files: uploads, plugins, updates, cache. In the official wordpress image PHP runs as www-data: in the apache variant it’s Apache’s user, in fpm the www pool’s. The Linux kernel compares numbers only: uid 33 in the container and uid 33 on the host are the same owner, even though their names live in different /etc/passwd files.

    Image PHP user uid:gid
    wordpress:apache, wordpress:fpm (Debian) www-data 33:33
    wordpress:fpm-alpine www-data 82:82

    On Ubuntu and Debian uid 33 is also called www-data, so there chown -R www-data:www-data and chown -R 33:33 do the same thing. With an -alpine image the host’s name doesn’t fit: you need 82:82, and ls -l on the host shows a bare number — Ubuntu has no user 82.

    Don’t guess the number, ask the container:

    docker compose exec wordpress id www-data
    uid=33(www-data) gid=33(www-data) groups=33(www-data)

    On first start the image’s entrypoint copies WordPress into an empty /var/www/html and hands the files to www-data right away; it also claims an empty root-owned directory that Docker created. Permissions break later: the site was moved from another server as your own user, an archive was unpacked as root, a backup was restored with foreign numbers.

    Can you change the owner to www-data

    Yes, if the directory holds only the site’s files — what’s mounted at /var/www/html:

    sudo chown -R 33:33 /opt/wordpress/wp_data

    Don’t run chown -R higher up the tree: neighbouring directories have their own owners — MariaDB data, for one, is uid 999 — and there’s no reason to give docker-compose.yaml and .env to the user the site runs as.

    Permissions

    An owner isn’t enough if static files are served by nginx from a neighbouring container: it reads the same directory (:ro) as its own user, uid 101, and needs read permission for everyone.

    sudo find /opt/wordpress/wp_data -type d -exec chmod 755 {} +
    sudo find /opt/wordpress/wp_data -type f -exec chmod 644 {} +

    Don’t use chmod 777: then any process on the server can write to the directory, and WordPress still asks for FTP — it looks at the owner, not the permissions.

    Everything to www-data, or just uploads

    If… Use
    you update core and plugins from the admin panel the whole site directory — 33:33
    the site is updated rarely and by hand, and you don’t trust the plugins files owned by root; www-data owns only wp-content/uploads (and the cache directory, if there is one)

    The first option is how the image works on its own. The cost: a hole in a plugin lets an attacker rewrite any PHP file on the site, core included. In the second, PHP writes only to uploads, but updates from the admin panel stop working: run them with WP-CLI as root: wp core update --allow-root, wp plugin update --all --allow-root. Without the flag WP-CLI refuses to run as root: YIKES! It looks like you're running this as root. The wordpress image has no WP-CLI — copy wp-cli.phar into the container as /usr/local/bin/wp. Then set DISALLOW_FILE_MODS in wp-config.php so the admin panel doesn’t offer what it can’t do.

    If it doesn’t work

    WordPress asks for FTP credentials when installing a plugin

    Cause
    The site’s files don’t belong to the PHP user. WordPress writes directly only if the owner of its own files matches the user PHP runs as; chmod 777 doesn’t pass that check.
    Fix
    chown -R 33:33 on the site directory (82:82 for -alpine). FS_METHOD direct in wp-config.php removes the FTP prompt but not the permissions problem: writes still fail with an error.

    Unable to create directory wp-content/uploads/2026/10. Is its parent directory writable by the server?

    Cause
    wp-content/uploads isn’t owned by www-data — most often after copying files as your own user (uid 1000) or unpacking an archive as root.
    Fix
    Give www-data all of wp-content/uploads and check with a write — see “How to check”.

    Ran chown www-data:www-data on the host, and WordPress still can’t write

    Cause
    An Alpine image: there www-data is uid 82, while the host’s www-data is 33.
    Fix
    Ask the container for the number, docker compose exec wordpress id www-data, and chown to those numbers.

    Pages open, but images and CSS return 403

    Cause
    Static files are served by nginx from a neighbouring container with its own user (nginx, uid 101). It can’t read files with 600 or directories with 700.
    Fix
    Directories 755, files 644: the commands are under “Permissions”.

    After restoring from backup the files have the wrong owner again

    Cause
    rsync -a and tar run as root keep the owner numbers from the source server.
    Fix
    After restoring, chown -R 33:33, or use rsync -a --chown=33:33 from the start.

    ls -l on the host shows the owner as 100033

    Cause
    Docker has userns-remap on: container IDs are shifted to the start of the range in /etc/subuid.
    Fix
    chown to the shifted number you see in ls -ln: with a range starting at 100000, chown -R 100033:100033. chown 33:33 doesn’t help here: to the container that’s a stranger.

    How to check

    Write to uploads as www-data — the same way PHP will:

    docker compose exec -u www-data wordpress touch /var/www/html/wp-content/uploads/.write-test
    docker compose exec -u www-data wordpress rm /var/www/html/wp-content/uploads/.write-test

    No errors — image uploads will work. Then look for files with a different owner; empty output means all is well:

    sudo find /opt/wordpress/wp_data ! -uid 33 | head

    Finally, install any plugin from the admin panel: it should go in without an FTP prompt.