Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 2.56 KB

File metadata and controls

55 lines (35 loc) · 2.56 KB

Using phpvm with your IDE

phpvm shell switches your terminal, but a GUI IDE doesn't read shell env vars. It pins its PHP interpreter in its own settings, snapshotted at IDE startup. So when you switch with phpvm shell or phpvm global, you also need to point the IDE at the right binary.

phpvm gives you three primitives so any IDE or tool can wire in:

phpvm which 8.2          # /usr/bin/php8.2  (single path, parseable)
phpvm --list --paths     # table: version + absolute path, active marker
phpvm --list --json      # [{"version":"8.2","path":"/usr/bin/php8.2","active":true}, ...]

Why not a per-IDE helper? IDE config formats move between versions and installs (Toolbox vs standalone vs flatpak vs portable). Writing config files for you is brittle. Printing the paths you need is forward-compatible: every IDE accepts an absolute interpreter path.

PhpStorm

Settings > PHP > CLI Interpreter > "+" > Local... and register one entry per installed version, using the rows from phpvm --list --paths. Name them PHP 8.1, PHP 8.2, etc. so the project picker stays readable.

Then per project: Settings > PHP > CLI Interpreter to the one matching .php-version. On PhpStorm 2023.2+, enable Settings > PHP > "Get PHP language level from composer.json / .php-version" so opening a project auto-picks the interpreter.

VS Code (Intelephense / PHP Tools)

Add to your workspace .vscode/settings.json:

{
  "php.validate.executablePath": "/usr/bin/php8.2",
  "intelephense.environment.phpVersion": "8.2"
}

The path comes from phpvm which 8.2. For multi-project setups, commit a per-project .vscode/settings.json alongside .php-version.

Sublime Text / Zed / Helix (LSP-Intelephense / phpactor)

Set the language server's phpExecutablePath (or equivalent) to the output of phpvm which <version>. The exact setting name varies by client, and the value is always an absolute path.

NetBeans

Tools > Options > PHP, register each installed version's path from phpvm --list --paths, then pick per project under Project Properties > PHP > Run Configuration.

Scripts and CI

# active version's binary
phpvm --list --json | jq -r '.[] | select(.active).path'

# all installed PHP binaries
phpvm --list --json | jq -r '.[].path'

# binary for the version this project pins (.php-version / composer.json)
phpvm which "$(phpvm --auto --print)"

phpvm --list --json is the contract for tooling: stable schema (version, path, active), one entry per installed PHP, dependency-free (no jq required to produce it, only to filter).