| name | wp-env |
| description | Local WordPress development environment management using @wordpress/env for plugin and theme development. Use this skill when setting up, configuring, starting, stopping, or managing wp-env Docker-based WordPress environments. |
wp-env - WordPress Local Development Environment
This skill provides assistance for working with wp-env, a tool that sets up local WordPress development environments using Docker with minimal configuration.
About wp-env
wp-env (@wordpress/env) creates Docker-based WordPress environments for plugin and theme development. It provides:
- Zero-config setup - Works out of the box for plugins and themes
- Dual environments - Separate development (port 8888) and testing (port 8889) instances
- Pre-configured tools - Includes WP-CLI, Composer, PHPUnit, and Xdebug
- Flexible configuration - Customize via
.wp-env.json for complex setups
Default Access:
Prerequisites Check
Before working with wp-env, verify these dependencies are installed and running:
docker --version
docker ps
node --version
npm --version
wp-env --version
If Docker is not running: Start Docker Desktop application first - wp-env cannot function without Docker.
If wp-env is not installed: Install globally with npm -g install @wordpress/env
Common Workflows
First-Time Environment Setup
When setting up wp-env for the first time in a plugin or theme directory:
docker ps
npm -g install @wordpress/env
cd /path/to/your/plugin
wp-env start
wp-env will automatically detect if the current directory is a plugin or theme and mount it appropriately.
Daily Development Operations
Starting the environment:
wp-env start
wp-env start --update
wp-env start --xdebug
Stopping the environment:
wp-env stop
Checking environment status:
docker ps
Running WP-CLI Commands
Execute WordPress CLI commands inside the environment using wp-env run:
wp-env run cli wp user list
wp-env run cli wp plugin install contact-form-7 --activate
wp-env run tests-cli wp post create --post_title="Test Post" --post_status=publish
wp-env run cli "wp rewrite structure /%postname%/"
wp-env run cli wp shell
Environment types:
cli / wordpress - Development environment (shares database with port 8888)
tests-cli / tests-wordpress - Testing environment (separate database, port 8889)
Working directory context:
By default, commands run from WordPress root. For plugin-specific commands, use --env-cwd:
wp-env run cli --env-cwd=wp-content/plugins/your-plugin composer install
wp-env run tests-cli --env-cwd=wp-content/plugins/your-plugin phpunit
Database Reset for Testing
Reset the database to clean state:
wp-env clean
wp-env clean development
wp-env clean all
⚠️ Warning: This permanently deletes all posts, pages, media, and custom data.
Viewing Logs
Monitor PHP errors and Docker container logs:
wp-env logs
wp-env logs tests
wp-env logs all
wp-env logs --watch=false
Working with Ports
If the default port 8888 conflicts with another service:
WP_ENV_PORT=3333 wp-env start
docker ps
Or configure ports in .wp-env.json:
{
"port": 3333,
"testsPort": 3334
}
Note: Environment variables take precedence over .wp-env.json values.
Quick Reference - Essential Commands
| Command | Description |
|---|
wp-env start | Start the environment |
wp-env start --update | Start and update WordPress/sources |
wp-env stop | Stop the environment |
wp-env clean [env] | Reset database (env: tests, development, all) |
wp-env destroy | Completely remove containers and data |
wp-env logs [env] | View logs (env: development, tests, all) |
wp-env run <container> <command> | Execute command in container |
wp-env install-path | Show where environment files are stored |
docker ps | Check which containers are running |
Common containers for wp-env run:
cli - WP-CLI, Composer, PHPUnit (development)
tests-cli - WP-CLI, Composer, PHPUnit (testing)
wordpress - WordPress PHP environment (development)
tests-wordpress - WordPress PHP environment (testing)
Configuration with .wp-env.json
Create a .wp-env.json file in your project root to customize the environment.
Common Configuration Patterns
Basic plugin development:
{
"plugins": ["."]
}
Custom WordPress version:
{
"core": "WordPress/WordPress#6.4.0",
"plugins": ["."]
}
Multi-plugin setup:
{
"plugins": [".", "WordPress/classic-editor", "../another-plugin"]
}
For complete configuration reference with 20+ examples, environment-specific overrides, custom mappings, multisite setup, and lifecycle scripts, see references/configuration-guide.md.
When Things Go Wrong
Common Errors
Error: "Error while running docker-compose command"
- Check that Docker Desktop is started and running
- Check Docker Desktop dashboard for logs, restart, or remove existing virtual machines
- Then try rerunning
wp-env start
Error: "Host is already in use by another container"
- The container you are attempting to start is already running, or another container is. You can stop an existing container by running
wp-env stop from the directory that you started it in
- If you do not remember the directory where you started
wp-env, you can stop all containers by running docker stop $(docker ps -q). This will stop all Docker containers, so use with caution
- Then try rerunning
wp-env start
For comprehensive troubleshooting including Ubuntu Docker setup, database issues, and advanced debugging, see references/troubleshooting.md.
Advanced Features
For detailed information on these features, see references/command-reference.md.
Xdebug: Enable step debugging with wp-env start --xdebug. Configure your IDE for port 9003.
PHPUnit: WordPress test files included. Run with wp-env run tests-cli --env-cwd=wp-content/plugins/your-plugin phpunit.
Composer: Execute commands with wp-env run cli --env-cwd=wp-content/plugins/your-plugin composer install.
Best Practices
Directory Context
- Run
wp-env start from your plugin or theme directory for automatic mounting
- Use
--env-cwd when running commands that need to execute in specific directories
- Use absolute paths when possible to avoid confusion
Development Workflow
- Start environment once per work session:
wp-env start
- Make code changes - they're immediately reflected (no rebuild needed)
- Use
wp-env run cli wp commands for WordPress operations
- Check logs when debugging:
wp-env logs
- Stop when done:
wp-env stop
Testing Workflow
- Use
tests-cli and tests-wordpress for isolated testing
- Reset test database frequently:
wp-env clean tests
- Keep test and development environments separate
- Use
wp-env clean all before running full integration tests
Configuration Management
- Keep
.wp-env.json in version control for team consistency
- Use
.wp-env.override.json (gitignored) for local-only overrides
- Document custom configurations in project README
Where Files Are Stored
wp-env stores files in a home directory (defaults vary by platform):
wp-env install-path
Override with WP_ENV_HOME environment variable:
WP_ENV_HOME="./local-wp-env" wp-env start
Additional Resources
External documentation: