You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the full list of shortcuts and their mappings, see [references/commands.md](references/commands.md).
25
+
For the full list of shortcuts and their mappings, run `ddev help`.
26
26
27
-
## Executing CLI Commands (Step-by-Step)
27
+
## DDEV Commands Work from Any Subdirectory
28
28
29
-
Always follow these steps before running any CLI tool (composer, npm, wp, drush, yarn, phpunit, etc.) in a DDEV project:
29
+
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:
30
30
31
-
### Step 1: Resolve the correct container path
31
+
```bash
32
+
ddev wp plugin list
33
+
ddev mailpit
34
+
ddev db
35
+
ddev composer show
36
+
ddev npm ls
37
+
ddev drush cr
38
+
ddev start
39
+
ddev describe
40
+
ddev ssh
41
+
```
42
+
43
+
No special flags or path resolution is needed for these commands.
44
+
45
+
## When `--dir` Scoping IS Required
32
46
33
-
Determine whether the working directory is the DDEV project root or a subdirectory. Run the bundled resolve script:
47
+
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`).
48
+
49
+
### Step 1: Resolve the container path
50
+
51
+
Run the bundled resolve script to map the host subdirectory to a container path:
34
52
35
53
```bash
36
54
scripts/resolve-ddev-root.sh "$(pwd)"
@@ -46,40 +64,33 @@ Output (JSON):
46
64
}
47
65
```
48
66
49
-
-`relative_path`**empty** -- working directory is the DDEV root, shortcuts work directly.
50
-
-`relative_path`**non-empty** -- working directory is a subdirectory, use `--dir` with the `container_path` value in all commands.
67
+
-`relative_path`**empty** -- working directory is the DDEV root, no `--dir` needed.
68
+
-`relative_path`**non-empty** -- use `--dir` with the `container_path` value for file-path-sensitive commands.
51
69
52
-
### Step 2: Execute command
70
+
### Step 2: Execute the scoped command
53
71
54
72
If DDEV is not running, start it first with `ddev start`.
55
73
56
-
**At the project root** (relative_path is empty) -- use DDEV shortcuts:
57
-
58
-
```bash
59
-
ddev composer install
60
-
ddev npm run build
61
-
ddev wp plugin list
62
-
ddev yarn add <pkg>
63
-
```
64
-
65
-
**From a subdirectory** (relative_path is non-empty) -- use `ddev exec --dir`:
66
-
67
74
```bash
75
+
# Install dependencies scoped to a plugin subdirectory
The`--dir` flag is required whenever the target directory differs from the container docroot (`/var/www/html`). Without it, commands run at the docroot and may operate on the wrong `composer.json`, `package.json`, or project context.
83
+
Without`--dir`, these commands run at the container docroot (`/var/www/html`)and operate on the wrong `composer.json`, `package.json`, or project context.
73
84
74
85
## Running Commands in Containers
75
86
76
-
Use `ddev exec` when a shortcut does not exist or when targeting a specific directory:
87
+
Use `ddev exec` when no shortcut exists or when you need to target a specific container directory:
77
88
78
89
```bash
79
-
#Default: runs in web container at docroot
90
+
#Runs in web container at docroot
80
91
ddev exec ls -la
81
92
82
-
#Specify a working directory inside the container
93
+
#Scope to a subdirectory for file-path-sensitive operations
@@ -89,15 +100,9 @@ ddev exec -s db mysql -e "SHOW DATABASES"
89
100
ddev . ls -la
90
101
```
91
102
92
-
Use `ddev ssh` for an interactive shell session.
93
-
94
-
## Subpath Mapping (Working from a Subdirectory)
95
-
96
-
A common scenario: the DDEV project is configured for a full application (e.g., a WordPress site at `~/Projects/mysite/`) but the agent runs from a subdirectory (e.g., `~/Projects/mysite/wp-content/plugins/my-plugin/`).
97
-
98
-
### The Problem
103
+
## Subpath Mapping (for `ddev exec --dir`)
99
104
100
-
DDEV commands must reference container paths relative to `/var/www/html` (the container docroot). When the working directory is a subdirectory of the DDEV project, the container path must be computed.
105
+
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.
101
106
102
107
### Resolving the DDEV Root
103
108
@@ -151,4 +156,5 @@ Example JSON output fields:
151
156
-**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.
152
157
153
158
### references/
154
-
-**commands.md** - Quick-reference table of all DDEV CLI shortcuts, lifecycle commands, database tools, and debugging commands.
159
+
-**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.
160
+
-**wordpress-multisite.md** - Setup guide for WordPress Multisite with DDEV, covering subdomains, different hostnames, and subdirectory configurations with WP-CLI commands.
0 commit comments