ddev

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

DDEV

DDEV

DDEV is a Docker-based local development tool for PHP/Node projects. It wraps common CLI tools (composer, npm, wp, drush, etc.) so they run inside containers without requiring local installation. Full docs: https://docs.ddev.com
DDEV是一款基于Docker的PHP/Node项目本地开发工具。它封装了常见的CLI工具(composer、npm、wp、drush等),无需本地安装即可在容器内运行。完整文档:https://docs.ddev.com

CLI Syntactic Sugar

CLI语法糖

DDEV provides shortcut commands that proxy to container-internal tools. Use these instead of
ddev exec
:
ddev composer install          # runs composer inside the container
ddev npm run build             # runs npm inside the container
ddev wp plugin list            # runs wp-cli (WordPress only)
ddev drush cr                  # runs drush (Drupal only)
ddev artisan migrate           # runs artisan (Laravel only)
ddev console cache:clear       # runs bin/console (Symfony only)
ddev yarn add <pkg>            # runs yarn inside the container
ddev php -v                    # runs PHP inside the container
For the full list of shortcuts and their mappings, run
ddev help
.
DDEV提供了代理到容器内部工具的快捷命令。请使用这些命令替代
ddev exec
ddev composer install          # 在容器内运行composer
ddev npm run build             # 在容器内运行npm
ddev wp plugin list            # 运行wp-cli(仅适用于WordPress)
ddev drush cr                  # 运行drush(仅适用于Drupal)
ddev artisan migrate           # 运行artisan(仅适用于Laravel)
ddev console cache:clear       # 运行bin/console(仅适用于Symfony)
ddev yarn add <pkg>            # 在容器内运行yarn
ddev php -v                    # 在容器内运行PHP
如需查看完整的快捷命令及其映射关系,请运行
ddev help

DDEV Commands Work from Any Subdirectory

DDEV命令可在任意子目录执行

DDEV automatically detects its project root from any subdirectory within the project tree. Most DDEV commands work out of the box regardless of where the shell is located:
bash
ddev wp plugin list
ddev mailpit
ddev db
ddev composer show
ddev npm ls
ddev drush cr
ddev start
ddev describe
ddev ssh
No special flags or path resolution is needed for these commands.
DDEV可自动从项目目录树中的任意子目录检测项目根目录。大多数DDEV命令无需额外配置,无论当前shell处于哪个目录都能直接运行:
bash
ddev wp plugin list
ddev mailpit
ddev db
ddev composer show
ddev npm ls
ddev drush cr
ddev start
ddev describe
ddev ssh
这些命令不需要特殊标志或路径解析。

When
--dir
Scoping IS Required

何时需要使用
--dir
指定目录

The
--dir
flag is only needed when running file-path-sensitive scripts via
ddev exec
that must target a specific subdirectory inside the container. This applies when the command operates on files relative to the working directory (e.g.,
composer install
reading a specific
composer.json
, or
npm install
reading a specific
package.json
).
只有当通过
ddev exec
运行对文件路径敏感的脚本,且必须指向容器内特定子目录时,才需要使用
--dir
标志。例如,命令需要读取相对工作目录的文件(如
composer install
读取特定的
composer.json
,或
npm install
读取特定的
package.json
)时。

Step 1: Resolve the container path

步骤1:解析容器路径

Run the bundled resolve script to map the host subdirectory to a container path:
bash
scripts/resolve-ddev-root.sh "$(pwd)"
Output (JSON):
json
{
  "project_root": "/Users/you/Projects/mysite",
  "container_path": "/var/www/html/wp-content/plugins/my-plugin",
  "relative_path": "wp-content/plugins/my-plugin",
  "project_name": "mysite"
}
  • relative_path
    empty -- working directory is the DDEV root, no
    --dir
    needed.
  • relative_path
    non-empty -- use
    --dir
    with the
    container_path
    value for file-path-sensitive commands.
运行内置的解析脚本,将主机子目录映射到容器路径:
bash
scripts/resolve-ddev-root.sh "$(pwd)"
输出(JSON格式):
json
{
  "project_root": "/Users/you/Projects/mysite",
  "container_path": "/var/www/html/wp-content/plugins/my-plugin",
  "relative_path": "wp-content/plugins/my-plugin",
  "project_name": "mysite"
}
  • relative_path
    为空——当前工作目录即为DDEV根目录,无需使用
    --dir
  • relative_path
    非空——请将
    container_path
    的值与
    --dir
    配合使用,以运行对文件路径敏感的命令。

Step 2: Execute the scoped command

步骤2:执行指定目录的命令

If DDEV is not running, start it first with
ddev start
.
bash
undefined
如果DDEV未运行,请先执行
ddev start
启动它。
bash
undefined

Install dependencies scoped to a plugin subdirectory

针对插件子目录安装依赖

ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install" ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "npm install"
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install" ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "npm install"

Run a script that reads files relative to the working directory

运行读取相对工作目录文件的脚本

ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "phpunit"

Without `--dir`, these commands run at the container docroot (`/var/www/html`) and operate on the wrong `composer.json`, `package.json`, or project context.
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "phpunit"

如果不使用`--dir`,这些命令会在容器的文档根目录(`/var/www/html`)运行,操作的是错误的`composer.json`、`package.json`或项目上下文。

Running Commands in Containers

在容器内运行命令

Use
ddev exec
when no shortcut exists or when you need to target a specific container directory:
bash
undefined
当没有快捷命令可用,或需要指向容器内特定目录时,请使用
ddev exec
bash
undefined

Runs in web container at docroot

在web容器的文档根目录运行

ddev exec ls -la
ddev exec ls -la

Scope to a subdirectory for file-path-sensitive operations

针对子目录运行对文件路径敏感的操作

ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install"
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install"

Run in the database container

在数据库容器内运行

ddev exec -s db mysql -e "SHOW DATABASES"
ddev exec -s db mysql -e "SHOW DATABASES"

Shorthand alias

简写别名

ddev . ls -la
undefined
ddev . ls -la
undefined

Subpath Mapping (for
ddev exec --dir
)

子路径映射(适用于
ddev exec --dir

Path resolution is only needed when using
ddev exec --dir
to scope file-path-sensitive scripts to a subdirectory. Standard DDEV commands (
ddev wp
,
ddev mailpit
,
ddev db
,
ddev start
, etc.) do not require this -- they work from any subdirectory automatically.
只有在使用
ddev exec --dir
将对文件路径敏感的脚本限定到子目录时,才需要进行路径解析。标准DDEV命令(如
ddev wp
ddev mailpit
ddev db
ddev start
等)无需此操作——它们可自动在任意子目录运行。

Resolving the DDEV Root

解析DDEV根目录

Use the bundled resolve script to find the DDEV project root and compute the container path:
bash
undefined
使用内置的解析脚本查找DDEV项目根目录并计算容器路径:
bash
undefined

From any subdirectory within a DDEV project

在DDEV项目内的任意子目录执行

scripts/resolve-ddev-root.sh /path/to/wp-content/plugins/my-plugin

The script walks up the directory tree looking for `.ddev/config.yaml`. If no argument is provided, it uses the current working directory.
scripts/resolve-ddev-root.sh /path/to/wp-content/plugins/my-plugin

该脚本会遍历目录树寻找`.ddev/config.yaml`文件。如果未提供参数,则使用当前工作目录。

Manual Path Computation

手动计算路径

If the script is unavailable, compute the path manually:
  1. Find the directory containing
    .ddev/config.yaml
    (the DDEV project root)
  2. Compute the relative path from that root to the current working directory
  3. Prepend
    /var/www/html/
    to get the container path
如果脚本不可用,可手动计算路径:
  1. 找到包含
    .ddev/config.yaml
    的目录(即DDEV项目根目录)
  2. 计算从该根目录到当前工作目录的相对路径
  3. 在相对路径前添加
    /var/www/html/
    ,即可得到容器路径

Project Information

项目信息

Use
ddev describe
to get detailed information about the current DDEV project. Add the
-j
flag to get structured JSON output:
bash
ddev describe -j
This provides useful details such as:
  • Project type (wordpress, drupal, laravel, etc.)
  • Primary URL and all project URLs
  • PHP version and Node.js version
  • Database type and version (mariadb, mysql, postgres)
  • Web server type (nginx-fpm, apache-fpm)
  • Service status for web, db, and additional services
  • Published ports for host-to-container mapping
Example JSON output fields:
  • type
    - Project type (wordpress, drupal, etc.)
  • primary_url
    - Main project URL
  • urls
    - Array of all project URLs (HTTP and HTTPS)
  • php_version
    - PHP version in use
  • nodejs_version
    - Node.js version in use
  • database_type
    - Database type (mariadb, mysql, postgres)
  • webserver_type
    - Web server (nginx-fpm, apache-fpm)
  • services
    - Status and details for each service
使用
ddev describe
获取当前DDEV项目的详细信息。添加
-j
标志可获取结构化JSON输出:
bash
ddev describe -j
该命令会提供以下有用信息:
  • 项目类型(wordpress、drupal、laravel等)
  • 主URL及所有项目URL
  • PHP版本Node.js版本
  • 数据库类型和版本(mariadb、mysql、postgres)
  • Web服务器类型(nginx-fpm、apache-fpm)
  • 服务状态(web、db及其他附加服务)
  • 发布端口(主机到容器的端口映射)
示例JSON输出字段:
  • type
    - 项目类型(wordpress、drupal等)
  • primary_url
    - 项目主URL
  • urls
    - 所有项目URL数组(HTTP和HTTPS)
  • php_version
    - 使用的PHP版本
  • nodejs_version
    - 使用的Node.js版本
  • database_type
    - 数据库类型(mariadb、mysql、postgres)
  • webserver_type
    - Web服务器(nginx-fpm、apache-fpm)
  • services
    - 各服务的状态和详细信息

Resources

资源

scripts/

scripts/

  • resolve-ddev-root.sh - Walks up the directory tree to find the DDEV project root from any subdirectory. Returns JSON with project root, container path, relative path, and project name.
  • resolve-ddev-root.sh - 遍历目录树,从任意子目录查找DDEV项目根目录。返回包含项目根目录、容器路径、相对路径和项目名称的JSON数据。

references/

references/

  • npm-projects.md - Running npm/Node.js dev servers in DDEV, including port exposure, host binding, and framework-specific examples for Vite, Next.js, and Astro.
  • wordpress-multisite.md - Setup guide for WordPress Multisite with DDEV, covering subdomains, different hostnames, and subdirectory configurations with WP-CLI commands.
  • npm-projects.md - 在DDEV中运行npm/Node.js开发服务器的指南,包括端口暴露、主机绑定以及Vite、Next.js和Astro等框架的具体示例。
  • wordpress-multisite.md - 使用DDEV搭建WordPress多站点的指南,涵盖子域名、不同主机名以及通过WP-CLI命令配置子目录的内容。