Skip to content

Commit 1e5a3ab

Browse files
chapterjasonclaude
andcommitted
Prewire Xdebug for workspace use
Xdebug is already baked in but unconfigured, which meant users had to hand-write ini settings every time they wanted to debug against an IDE on the host. New scripts/php/xdebug.ini sets mode=off (zero overhead until flipped), client_host=host.docker.internal, start_with_request=trigger, and discover_client_host=true. Layered on top of Sury's 20-xdebug.ini via the 99-xdebug-workspace.ini filename in every SAPI conf.d that loads xdebug. Staged alongside workspace.ini at /usr/local/share/php-workspace so pvm applies it to versions installed later too. With this in place, debugging is just: XDEBUG_MODE=debug php app.php or sending XDEBUG_TRIGGER via cookie/query/env at request time. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c02cc6c commit 1e5a3ab

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

scripts/php/install.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,21 @@ rm -rf /var/lib/apt/lists/*
4545

4646
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4747

48-
# Dev-oriented php.ini overrides. Staged at a known path so pvm can reuse
49-
# it when installing additional PHP versions later.
48+
# Workspace overrides (dev php.ini + xdebug tuning). Staged at a known
49+
# path so pvm can reuse them when installing additional PHP versions.
5050
install -m 0755 -d /usr/local/share/php-workspace
5151
install -m 0644 "$script_dir/workspace.ini" /usr/local/share/php-workspace/workspace.ini
52+
install -m 0644 "$script_dir/xdebug.ini" /usr/local/share/php-workspace/xdebug.ini
5253

5354
# Apply to every SAPI (cli, fpm, apache2, ...) of the default version that
54-
# got installed. 99- prefix so it loads last and wins over Sury defaults.
55+
# got installed. 99- prefix so they load last and win over Sury defaults.
56+
# xdebug override only lands where xdebug is actually enabled for the SAPI.
5557
for sapi_dir in /etc/php/"$PHP_DEFAULT_VERSION"/*/conf.d; do
5658
[ -d "$sapi_dir" ] || continue
5759
install -m 0644 /usr/local/share/php-workspace/workspace.ini "$sapi_dir/99-workspace.ini"
60+
if ls "$sapi_dir"/*xdebug.ini >/dev/null 2>&1; then
61+
install -m 0644 /usr/local/share/php-workspace/xdebug.ini "$sapi_dir/99-xdebug-workspace.ini"
62+
fi
5863
done
5964

6065
# pvm — user-level PHP version switcher. Lives next to this installer; see

scripts/php/pvm

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,19 @@ cmd_install() {
130130
# shellcheck disable=SC2086
131131
sudo apt-get install -y --no-install-recommends --no-install-suggests $pkgs
132132

133-
# Layer the staged workspace overrides (dev errors, no memory cap, ...)
134-
# over every SAPI dir this version created. Staged by scripts/php/install.sh
135-
# at image build time.
136-
if [ -r /usr/local/share/php-workspace/workspace.ini ]; then
137-
for sapi_dir in /etc/php/"$ver"/*/conf.d; do
138-
[ -d "$sapi_dir" ] || continue
133+
# Layer the staged workspace overrides (dev errors, no memory cap,
134+
# xdebug tuning) over every SAPI dir this version created. Staged by
135+
# scripts/php/install.sh at image build time. The xdebug overlay only
136+
# lands where xdebug is enabled for the SAPI.
137+
for sapi_dir in /etc/php/"$ver"/*/conf.d; do
138+
[ -d "$sapi_dir" ] || continue
139+
if [ -r /usr/local/share/php-workspace/workspace.ini ]; then
139140
sudo install -m 0644 /usr/local/share/php-workspace/workspace.ini "$sapi_dir/99-workspace.ini"
140-
done
141-
fi
141+
fi
142+
if [ -r /usr/local/share/php-workspace/xdebug.ini ] && ls "$sapi_dir"/*xdebug.ini >/dev/null 2>&1; then
143+
sudo install -m 0644 /usr/local/share/php-workspace/xdebug.ini "$sapi_dir/99-xdebug-workspace.ini"
144+
fi
145+
done
142146

143147
echo "PHP $ver installed. Activate with: pvm use $ver"
144148
}

scripts/php/xdebug.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; Xdebug defaults for workspace use. Sury's 20-xdebug.ini already loads
2+
; the extension (zend_extension=xdebug.so) — this file only tunes runtime
3+
; behavior on top. Loaded via the 99-xdebug-workspace.ini filename so it
4+
; wins over Sury's own config.
5+
;
6+
; mode=off means zero overhead by default: enable per-run with
7+
; XDEBUG_MODE=debug php …
8+
; or per-request with the XDEBUG_TRIGGER cookie / GET / POST / env var.
9+
;
10+
; client_host=host.docker.internal targets the Docker host running the
11+
; workspace container; discover_client_host finds the right IP if the
12+
; IDE is elsewhere on the network.
13+
xdebug.mode = off
14+
xdebug.client_host = host.docker.internal
15+
xdebug.start_with_request = trigger
16+
xdebug.discover_client_host = true
17+
xdebug.log_level = 0

0 commit comments

Comments
 (0)