wp-env lets you easily set up a local WordPress environment for building and testing plugins and themes. It requires no configuration and runs on Docker or WordPress Playground.
Quick Start
1
Navigate to your plugin directory
2
Install wp-env globally
3
Start the environment
4
Access WordPress
Open http://localhost:8888 in your browser.Credentials:
- Username:
admin - Password:
password
- User:
root - Password:
password
Prerequisites
Docker (default runtime)
Docker (default runtime)
Node.js
Node.js
Install Node.js using a version manager like nvm or download directly.Required versions:
- Node.js: >= 18.12.0
- npm: >= 8.19.2
Git
Git
Git is used for downloading WordPress, plugins, and themes from source control.Install Git
Installation
Global Installation
Installwp-env globally to use it across all projects:
wp-env from any directory.
Local Installation
Install as a project dependency:When using npm scripts, add
-- before flags to pass them to wp-env instead of npm.Runtime Options
Docker Runtime (Default)
The default Docker runtime provides full features:WordPress Playground Runtime (Experimental)
Playground runs WordPress in WebAssembly without Docker:Once started with a runtime, wp-env automatically uses the same runtime for subsequent commands until destroyed.
Commands
wp-env start
Installs and initializes the WordPress environment.Start Command Options
Start Command Options
--update- downloads source updates and re-applies WordPress configuration--runtime=<docker|playground>- select runtime to use--xdebug[=<mode>]- enables Xdebug (default mode:debug)--spx[=<mode>]- enables SPX profiling (default mode:enabled)--scripts- execute configured lifecycle scripts (default:true)--auto-port- automatically find available ports when configured ports are busy--debug- enable debug output
Terminal
Terminal
wp-env stop
Stops the WordPress environment and frees ports.Terminal
wp-env reset
Resets the WordPress database.environment- which databases to reset (choices:all,development,tests, default:development)
--scripts- execute lifecycle scripts (default:true)--debug- enable debug output
Terminal
wp-env run
Runs arbitrary commands in Docker containers.This command is not available with the Playground runtime.
cli- WordPress CLI container (includes composer, phpunit, wp-cli)wordpress- WordPress web servermysql- MySQL databasecomposer- Composer containerphpmyadmin- phpMyAdmin container
--env-cwd=<path>- working directory inside container (default: WordPress root)--debug- enable debug output
Run Command Examples
Run Command Examples
Use
-- before conflicting options: wp-env run cli php -- --helpwp-env cleanup
Cleans up the WordPress environment, removing containers, volumes, and networks but preserving Docker images.--scripts- execute lifecycle scripts (default:true)--force- skip confirmation prompt--debug- enable debug output
wp-env destroy
Completely destroys the WordPress environment including Docker images.--scripts- execute lifecycle scripts (default:true)--force- skip confirmation prompt--debug- enable debug output
wp-env logs
Displays PHP and Docker logs.environment- which environment logs to display (default:development)
--watch- watch for logs as they happen (default:true)--debug- enable debug output
Terminal
wp-env status
Displays status, URLs, ports, and configuration.Terminal
--json- output status as JSON--debug- enable debug output
Configuration
.wp-env.json
Create a.wp-env.json file to customize your environment:
Configuration Fields
Source Types
You can specify various source types forcore, plugins, and themes:
Default wp-config Values
These constants are set by default in the development instance:.wp-env.json:
.wp-env.json
.wp-env.override.json
Create this file (typically git-ignored) for local development overrides:.wp-env.override.json
The
config and mappings fields are merged; all other fields override completely.Lifecycle Scripts
Execute commands at specific points in the lifecycle:.wp-env.json
afterStart- runs afterwp-env startafterReset- runs afterwp-env resetafterCleanup- runs afterwp-env cleanupafterDestroy- runs afterwp-env destroy
Environment-Specific Configuration
Use theenv key to override settings for specific environments:
.wp-env.json
Advanced Usage
Running Parallel Environments
Run multiple wp-env instances from the same folder using different config files:1
Create custom config files
staging.json
2
Start each environment
Terminal
3
Manage environments separately
Terminal
Using Xdebug
Enable Xdebug for step debugging:1
Start with Xdebug enabled
2
Configure your IDE
Example VS Code
launch.json:.vscode/launch.json
3
Start debugging
- Launch the debugger in your IDE
- Set a breakpoint in your PHP code
- Refresh your browser at http://localhost:8888
- The breakpoint should trigger
Xdebug is only available for PHP 7.2+ (the default version).
Using SPX Profiling
SPX provides low-overhead profiling with a web UI:1
Enable SPX
2
Access SPX UI
Visit any page with SPX query parameters:
3
Analyze performance
From the SPX interface you can:
- Enable profiling for requests
- View flame graphs
- Analyze function timelines
- Examine memory usage
Adding mu-plugins
Use themappings config to add mu-plugins:
.wp-env.json
Custom PHP Settings
Map an.htaccess file to customize PHP settings:
1
Configure mapping
.wp-env.json
2
Create .htaccess file
.htaccess
Environment Variables
Override configuration using environment variables:WP_ENV_HOME- wp-env home directory (default:~/.wp-env)WP_ENV_PORT- development environment portWP_ENV_TESTS_PORT- test environment portWP_ENV_PHPMYADMIN_PORT- phpMyAdmin portWP_ENV_MYSQL_PORT- MySQL portWP_ENV_CORE- WordPress version to useWP_ENV_PHP_VERSION- PHP version to useWP_ENV_LIFECYCLE_SCRIPT_<EVENT>- lifecycle script commandsCI- when set, disables automatic port selection
Troubleshooting
Check wp-env is running
Check wp-env is running
wordpress and mariadb.Check port number
Check port number
PORTS column to see which port wp-env is using.Change port if needed:Restart with updates
Restart with updates
Restart Docker
Restart Docker
- Click Docker icon in system tray
- Select “Restart”
- Run
wp-env startagain
Reset the database
Reset the database
Destroy and start fresh
Destroy and start fresh
Package Information
- Version: 11.0.0
- Node.js: >= 18.12.0
- npm: >= 8.19.2
- License: GPL-2.0-or-later
Related Packages
- @wordpress/scripts - Build and test scripts
- @wordpress/create-block - Block scaffolding tool
- @wordpress/e2e-test-utils-playwright - E2E testing utilities