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
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:| Feature | Docker | Playground |
|---|---|---|
| Requires Docker | Yes | No |
| Xdebug | Yes | Yes |
| SPX profiling | Yes | No |
| phpMyAdmin | Yes | Yes |
| MySQL database | Yes | No (SQLite) |
| Multisite | Yes | Yes |
| Custom PHP version | Yes | Yes |
| Plugin/theme mounting | Yes | Yes |
wp-env run command | Yes | No |
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
| Field | Type | Default | Description |
|---|---|---|---|
core | string|null | null | WordPress installation to use (null = latest production) |
phpVersion | string|null | null | PHP version to use |
plugins | string[] | [] | Plugins to install and activate |
themes | string[] | [] | Themes to install |
port | integer | 8888 | Port number for the installation |
testsPort | integer | 8889 | Port number for test site |
autoPort | boolean | false | Auto-find available ports |
config | Object | See below | wp-config.php constants |
mappings | Object | {} | Directory mappings to mount |
mysqlPort | integer | random | MySQL port to expose |
phpmyadmin | boolean | false | Enable phpMyAdmin |
phpmyadminPort | integer | random | phpMyAdmin port |
multisite | boolean | false | Enable multisite |
lifecycleScripts | Object | {} | Lifecycle commands |
Source Types
You can specify various source types forcore, plugins, and themes:
| Type | Format | Example |
|---|---|---|
| Relative path | .<path>|~<path> | "./a/directory", "~/a/directory" |
| Absolute path | /<path>|<letter>:\<path> | "/a/directory", "C:\\a\\directory" |
| GitHub repo | <owner>/<repo>[/<path>][#<ref>] | "WordPress/WordPress", "WordPress/gutenberg#trunk" |
| SSH repo | ssh://user@host/<owner>/<repo>.git[#<ref>] | "ssh://[email protected]/WordPress/WordPress.git" |
| ZIP file | http[s]://<host>/<path>.zip | "https://wordpress.org/wordpress-5.4-beta2.zip" |
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:
Each config file gets isolated Docker containers and data.
Using Xdebug
Enable Xdebug for step debugging: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:Adding mu-plugins
Use themappings config to add mu-plugins:
.wp-env.json
Custom PHP Settings
Map an.htaccess file to customize PHP settings:
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