|
| 1 | +# php-debugger installer |
| 2 | + |
| 3 | +A cross-platform command-line installer for the [PHP debugger](https://github.com/php-debugger/php-debugger). |
| 4 | +It installs either a self-contained PHP interpreter with the debugger compiled in |
| 5 | +(the default), or just the debugger extension into your existing PHP. It always |
| 6 | +pulls the **latest release** and auto-detects your OS and architecture. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +Build from source (Go 1.25+): |
| 11 | + |
| 12 | +```bash |
| 13 | +go build -o php-debugger . |
| 14 | +# optionally move it onto your PATH |
| 15 | +mv php-debugger /usr/local/bin/ # or ~/.local/bin, etc. |
| 16 | +``` |
| 17 | + |
| 18 | +## Quick start |
| 19 | + |
| 20 | +```bash |
| 21 | +# Install the latest debugger interpreter (replacing your current php, with a backup) |
| 22 | +php-debugger install |
| 23 | + |
| 24 | +# Or install just the extension into your current php |
| 25 | +php-debugger install --extension-only |
| 26 | + |
| 27 | +# Switch the active PHP version (installs it if needed) |
| 28 | +php-debugger switch 8.4 |
| 29 | + |
| 30 | +# Update to the latest release |
| 31 | +php-debugger update |
| 32 | + |
| 33 | +# Remove it (restoring the interpreter you had before, if any) |
| 34 | +php-debugger uninstall |
| 35 | +``` |
| 36 | + |
| 37 | +## Commands |
| 38 | + |
| 39 | +| Command | What it does | |
| 40 | +| --- | --- | |
| 41 | +| `install` | Install the debugger **interpreter** (default) or the **extension** (`-e`). | |
| 42 | +| `switch <version>` | Make an installed version active, installing it first if needed. | |
| 43 | +| `update` | Reinstall the active interpreter and/or extension against the latest release. | |
| 44 | +| `uninstall [version]` | Remove an interpreter (or the extension), restoring any backup. | |
| 45 | + |
| 46 | +### Flags |
| 47 | + |
| 48 | +Global: |
| 49 | + |
| 50 | +- `-u, --user` — install into a per-user directory (no sudo). Default is system-wide. |
| 51 | +- `-y, --yes` — assume "yes" for prompts (non-interactive / CI). |
| 52 | +- `-V, --verbose` — extra output. |
| 53 | + |
| 54 | +`install`: |
| 55 | + |
| 56 | +- `-p, --php <x.y>` — PHP version to install (default: latest; interpreter only). |
| 57 | +- `-z, --zts` — thread-safe build (default: non-thread-safe; interpreter only). |
| 58 | +- `-e, --extension-only` — install only the extension into the current php. |
| 59 | + |
| 60 | +`update` / `uninstall`: |
| 61 | + |
| 62 | +- `-e, --extension` / `-i, --interpreter` — pick the target when both are installed. |
| 63 | +- `uninstall` also takes an optional `<version>` and `-z, --zts` to target a variant. |
| 64 | + |
| 65 | +## Install locations |
| 66 | + |
| 67 | +Interpreters are installed under a versioned directory and the active one is |
| 68 | +symlinked onto your PATH. |
| 69 | + |
| 70 | +**System-wide (default, needs sudo/admin):** |
| 71 | + |
| 72 | +| Platform | Install root | Active `php` | |
| 73 | +| --- | --- | --- | |
| 74 | +| macOS arm64 | `/opt/php-debugger` | `/opt/homebrew/bin` (or `/usr/local/bin`) | |
| 75 | +| macOS Intel / Linux | `/usr/local/php-debugger` | `/usr/local/bin` | |
| 76 | +| Windows | `%ProgramFiles%\php-debugger` | `<root>\bin` | |
| 77 | + |
| 78 | +**Per-user (`--user`, no sudo):** |
| 79 | + |
| 80 | +| Platform | Install root | Active `php` | |
| 81 | +| --- | --- | --- | |
| 82 | +| macOS | `~/Library/Application Support/php-debugger` | `~/.local/bin` | |
| 83 | +| Linux | `$XDG_DATA_HOME` or `~/.local/share/php-debugger` | `~/.local/bin` | |
| 84 | +| Windows | `%LOCALAPPDATA%\php-debugger` | `<root>\bin` | |
| 85 | + |
| 86 | +If the chosen bin directory isn't on your `PATH`, the installer prints the exact |
| 87 | +line to add. |
| 88 | + |
| 89 | +## How it works |
| 90 | + |
| 91 | +- **Verification first.** The downloaded interpreter is run (`php -v`) before any |
| 92 | + change is made. If it can't run on your system, nothing is installed and you're |
| 93 | + advised to use `--extension-only` or build from source. |
| 94 | +- **Replace with a backup.** If you already have a `php`, it is backed up and |
| 95 | + replaced in place, so `php` immediately resolves to the debugger build. |
| 96 | + `uninstall` restores it. |
| 97 | +- **Config carried over.** Your existing ini configuration is copied to the new |
| 98 | + interpreter's config path. Xdebug loaders are removed (the debugger provides its |
| 99 | + own simulated xdebug), other extension loaders are commented out (a |
| 100 | + self-contained build can't load foreign `.so` files), and `xdebug.mode` is |
| 101 | + constrained to `off`/`debug` (with a prompt if other modes are present). |
| 102 | +- **Post-install check + rollback.** After activating, it confirms the new `php` |
| 103 | + runs and reports the `php_debugger` module. Any failure rolls everything back to |
| 104 | + the prior working state. |
| 105 | +- **Multiple versions coexist.** `switch` flips the active version instantly via |
| 106 | + the symlink; installed versions are kept side by side. |
| 107 | + |
| 108 | +## Platform support |
| 109 | + |
| 110 | +Linux, macOS and Windows; x86_64 and arm64. On Windows, where symlinks require |
| 111 | +elevated privileges, the active `php` falls back to a generated `.cmd` shim. On |
| 112 | +Apple Silicon, an x86_64 build still installs native arm64 binaries. |
| 113 | + |
| 114 | +## Development |
| 115 | + |
| 116 | +```bash |
| 117 | +go build ./... |
| 118 | +go test -race ./... |
| 119 | +gofmt -l . |
| 120 | +``` |
| 121 | + |
| 122 | +The code is organized under `internal/`: `platform` (OS/arch, paths, symlinks), |
| 123 | +`release` (GitHub API + asset selection), `php` (interpreter introspection), |
| 124 | +`ini` (config rewriting), `manifest` (on-disk state), `installer` (orchestration), |
| 125 | +and `cli` (commands). A hidden `php-debugger resolve` command prints what would be |
| 126 | +downloaded for the current host — handy for debugging. |
0 commit comments