This guide explains how to set up local development for WordPress themes and plugins using Docker and Composer, allowing you to override remote packages with local development versions.
Your local development setup should follow this structure:
~/Folder-Name-Not-Important/ # Your main code directory
├── WP-GCU-News-v2/ # This project
├── WP-Theme-GCU-News/ # Local theme repository
├── WP-Plugin-Blog-Posts/ # Local plugin repository
├── WP-Plugin-Event-Card/ # Local plugin repository
├── WP-Theme/ # Local Base theme repository
└── [Other WP projects...] # Other WordPress projects
Create a docker-compose.override.yml file in your project root to add the volume mount for local development:
version: "3"
services:
web:
volumes:
# Mount parent directory containing all sibling projects for local development
- ../:/var/www/codeImportant:
- This file is gitignored, so each developer creates their own
- The
../:/var/www/codemount makes all sibling directories available inside the Docker container at/var/www/code/ - Docker Compose automatically merges this with the main
docker-compose.yml
Add path repositories to your composer.json repositories section. Place these at the top of the repositories array so they take priority over remote repositories:
{
"repositories": [
{
"type": "path",
"url": "/var/www/code/WP-Theme-GCU-News",
"options": {
"symlink": true
}
},
{
"type": "path",
"url": "/var/www/code/WP-Plugin-Blog-Posts",
"options": {
"symlink": true
}
},
// ... your existing remote repositories
]
}That's it! Composer will automatically use your local packages when they match the package names in your require section, regardless of the version constraints.
The Docker container maps directories as follows:
| Host Path | Container Path | Purpose |
|---|---|---|
./ (current project) |
/var/www/html |
Main WordPress project |
../ (parent directory) |
/var/www/code |
Access to sibling projects |
../WP-Theme-GCU-News |
/var/www/code/WP-Theme-GCU-News |
Local theme repository |
- Ensure your local repositories exist in the expected locations
- Start the Docker stack if not already running:
just up- Install/update packages using the just command:
# Install all packages
just composer install
# Update packages
just composer update
# Install specific package
just composer "require gce/gce-base-gcu-news"Composer will automatically use your local packages instead of downloading from remote repositories.
Check that your local packages are being used:
# Check installed packages
just composer show
# Verify specific package source (verbose output)
just composer "show gce/gce-base-gcu-news -v"Local packages will show a source type of path instead of dist.
To temporarily use remote packages:
- Comment out or remove the path repository from
composer.json - Run
just composer update
To switch back to local:
- Restore the path repository
- Run
just composer update
If you get errors like:
The `url` supplied for the path (/var/www/code/WP-Theme-GCU-News) repository does not exist
Solutions:
- Verify the local repository exists in your Code directory
- Check the path in composer.json matches the actual directory name
- Ensure the directory contains a valid
composer.jsonfile
If the container can't find /var/www/code/:
- Ensure you have created the
docker-compose.override.ymlfile with the volume mount - Restart the container:
just down && just up - Check container mounts:
just composer "exec ls -la /var/www/code"
If you get version constraint conflicts:
- Clear composer cache:
just composer clear-cache - Delete vendor directory and reinstall:
just composer "exec rm -rf vendor" && just composer install - If the local package version doesn't satisfy constraints, you may need to update the version in your local package's
composer.json
For developers setting up this project for the first time:
# 1. Clone the project
git clone [repository-url] WP-GCU-News-v2
cd WP-GCU-News-v2
# 2. Create docker-compose.override.yml for local development (if needed)
# See step 1 in setup instructions above
# 3. Initial setup (includes composer install)
just init
# 4. If you have local packages, add them to composer.json and update
just composer updateFor ongoing development:
# Start the stack
just up
# Install/update packages
just composer install
just composer update
# Stop the stack
just down- Code directory structure matches expected layout
- Local repositories exist and contain valid composer.json files
- Created
docker-compose.override.ymlwith parent directory mount (../:/var/www/code) - Composer repositories section includes path repositories with correct paths
- Container can access
/var/www/codedirectory
version: "3"
services:
web:
volumes:
# Mount parent directory containing all sibling projects for local development
- ../:/var/www/code"repositories": [
{
"type": "path",
"url": "/var/www/code/WP-Theme-GCU-News",
"options": {
"symlink": true
}
},
{
"type": "composer",
"url": "https://wpackagist.org",
"only": ["wpackagist-plugin/*", "wpackagist-theme/*"]
}
]This setup provides a seamless development experience where local packages are automatically used when available, similar to npm's yalc functionality.