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 777doesn’t pass that check. - Fix
chown -R 33:33on the site directory (82:82for-alpine).FS_METHODdirectinwp-config.phpremoves 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/uploadsisn’t owned bywww-data— most often after copying files as your own user (uid 1000) or unpacking an archive as root.- Fix
- Give
www-dataall ofwp-content/uploadsand 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-datais uid 82, while the host’swww-datais 33. - Fix
- Ask the container for the number,
docker compose exec wordpress id www-data, andchownto 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 with600or directories with700. - Fix
- Directories
755, files644: the commands are under “Permissions”.
After restoring from backup the files have the wrong owner again
- Cause
rsync -aandtarrun as root keep the owner numbers from the source server.- Fix
- After restoring,
chown -R 33:33, or usersync -a --chown=33:33from the start.
ls -l on the host shows the owner as 100033
- Cause
- Docker has
userns-remapon: container IDs are shifted to the start of the range in/etc/subuid. - Fix
chownto the shifted number you see inls -ln: with a range starting at 100000,chown -R 100033:100033.chown 33:33doesn’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.