wp-env 是一个基于 Docker 的工具,用于快速搭建本地 WordPress 环境,无需额外配置,适用于插件和主题的开发与测试。
The @wordpress/env package (wp-env) lets you set up a local WordPress environment (site) for building and testing plugins and themes, without any additional configuration.
Before following this guide, install Node.js development tools if you have not already done so.

npm -g install @wordpress/env in the terminal to install wp-env globally.wp-env start in the terminal to start the local WordPress environment.http://localhost:8888/wp-admin and log into the WordPress dashboard using username admin and password password.The wp-env tool uses Docker to create a virtual machine that runs the local WordPress site. The Docker Desktop application is free for small businesses, personal use, education, and non-commercial open-source projects. See their FAQ for more information.
Use the links below to download and install Docker Desktop for your operating system.
If you are using a version of Ubuntu prior to 20.04.1, see the additional troubleshooting notes below.
After successful installation, start the Docker Desktop application and follow the prompts to get set up. You should generally use the recommended (default) settings, and creating a Docker account is optional.
wp-envThe wp-env tool is used to create a local WordPress environment with Docker. So, after you have set up Docker Desktop, open the terminal and install the wp-env by running the command:
npm -g install @wordpress/env
This will install the wp-env globally, allowing the tool to be run from any directory. To confirm it’s installed and available, run wp-env --version, and the version number should appear.
Next, navigate to an existing plugin directory, theme directory, or a new working directory in the terminal and run:
wp-env start
Once the script completes, you can access the local environment at: http://localhost:8888. Log into the WordPress dashboard using username admin and password password.
wp-env configurations, and the documentation might prompt you to run npm run wp-env start instead.
For more information on controlling the Docker environment, see the @wordpress/env package readme.
wp-envThe wp-env tool can run from practically anywhere. When using the script while developing a single plugin, wp-env start can mount and activate the plugin automatically when run from the directory containing the plugin. This also works for themes when run from the directory in which you are developing the theme.
A generic WordPress environment will be created if you run wp-env start from a directory that is not a plugin or theme. The script will display the following warning, but ignore if this is your intention.
!! Warning: could not find a .wp-env.json configuration file and could not determine if 'DIR' is a WordPress installation, a plugin, or a theme.
You can also use the .wp-env.json configuration file to create an environment that works with multiple plugins and/or themes. See the @wordpress/env package readme for more configuration details.
wp-envHere are a few instructions if you need to start over or want to remove what was installed.
wp-env clean allwp-env destroywp-env tool, run npm -g uninstall @wordpress/envWhen using wp-env, it’s common to get the error: Error while running docker-compose command
wp-env start.If you see the error: Host is already in use by another container
wp-env stop from the directory that you started it in.wp-env, you can stop all containers by running docker stop $(docker ps -q). This will stop all Docker containers, so use with caution.wp-env start.If you are using a version of Ubuntu prior to 20.04.1, you may encounter errors when setting up a local WordPress environment with wp-env.
To resolve this, start by following the installation guide from Docker. docker-compose is also required, which you may need to install separately. Refer to the Docker compose documentation.
Once Docker and wp-env are installed, and assuming wp-env is configured globally, try running wp-env start in a directory. If you run into this error:
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
First, make sure Docker is running. You can check by running ps -ef | grep docker, which should return something like:
/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
If Docker is not running, try starting the service by running sudo systemctl start docker.service.
If Docker is running, then it is not listening to how the WordPress environment is trying to communicate. Try adding the following service override file to include listening on tcp. See this Docker documentation on how to configure remote access for Docker daemon.
# /etc/systemd/system/docker.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2376
Restart the service from the command-line:
sudo systemctl daemon-reload
sudo systemctl restart docker.service
After restarting the services, set the environment variable DOCKER_HOST and try starting wp-env with:
export DOCKER_HOST=tcp://127.0.0.1:2376
wp-env start
Your environment should now be set up at http://localhost:8888.
wp-env Basics diagram (Excalidraw)