Docker部署WordPress插件上传遇阻:Mac下Compose配置后需FTP凭证
Hey there! Let's sort out that annoying FTP credential prompt you're getting when trying to upload plugins to your Dockerized WordPress site. I've dealt with this exact issue using similar Docker-Compose configs, so here are a few straightforward solutions to get you up and running:
1. Force WordPress to Use Direct File System Access
The most common fix is telling WordPress to skip FTP and use direct file writes by adding a line to your wp-config.php file. Here's how to do it properly:
Option A: Edit the Container's wp-config.php Temporarily
First, get into your running WordPress container (replace <container-name> with your actual container name—you can find it with docker ps):
docker exec -it <container-name> bash
Once inside, open wp-config.php with a text editor (nano is user-friendly):
nano /var/www/html/wp-config.php
Scroll to the end of the file and add this line:
define('FS_METHOD', 'direct');
Save the file (Ctrl+O, then Enter) and exit nano (Ctrl+X). Now refresh your WordPress admin and try uploading a plugin again—the FTP prompt should be gone.
Option B: Persist the Config (Recommended)
To make this change stick even if you restart or rebuild your container, copy the wp-config.php file from the container to your local project directory:
docker cp <container-name>:/var/www/html/wp-config.php ./
Edit the local wp-config.php file and add the same FS_METHOD line as above. Then update your docker-compose.yml to mount this local file into the container:
In the wordpress service's volumes section, add:
- ./wp-config.php:/var/www/html/wp-config.php:delegated
Restart your containers to apply the change:
docker-compose down && docker-compose up -d
2. Fix File Permissions
Sometimes the issue comes down to incorrect file ownership in the container. WordPress runs as the www-data user, so make sure it has write access to the wp-content directory:
docker exec -it <container-name> chown -R www-data:www-data /var/www/html/wp-content
This command recursively sets the correct owner for all files and folders in wp-content, allowing WordPress to write directly without needing FTP.
3. Adjust Your Docker Volume Mounts
Right now, your config only mounts your theme directory to the container. Plugins get uploaded to /var/www/html/wp-content/plugins, which is stored inside the container (and will be lost if you rebuild it). To fix this and avoid permission issues long-term, mount the entire wp-content directory to your local project:
- Create a
wp-contentfolder in your project root:
mkdir wp-content
- Update the
wordpressservice'svolumesindocker-compose.ymlto replace your theme mount with:
volumes: - ./wp-content:/var/www/html/wp-content:delegated
- Restart your containers:
docker-compose down && docker-compose up -d
Now all themes, plugins, and uploads will be stored locally, and you'll avoid permission conflicts that trigger the FTP prompt.
Content of this question comes from Stack Exchange, asked by joshmoto

