ProcessWire CLI via ddev
All PHP CLI commands must run through ddev to use the web container's PHP interpreter.
Basic Commands
bash
ddev php script.php # Run PHP script ddev php --version # Check PHP version ddev exec php script.php # Execute in web container ddev ssh # Interactive shell
Bootstrapping ProcessWire
Include ./index.php from project root to get the full PW API ($pages, $page, $config, $sanitizer, etc.).
All CLI script files must be placed in ./cli_scripts/.
bash
# Inline one-liner
ddev exec php -r "namespace ProcessWire; include('./index.php'); echo PHP_EOL.'Count: '.pages()->count('template=product');"
bash
# Script file ddev php cli_scripts/myscript.php
One-liner rules:
- •Use functions API (
pages(),templates(),modules()) to avoid bash$variable expansion - •Escape local variables with
\$var - •Prefix output with
PHP_EOLto separate from RockMigrations log noise
Reference Files
- •CLI scripts and one-liners — conventions, examples, script file patterns
- •TracyDebugger — CLI debugging with
d(), browser snippets withbd() - •Database queries — direct SQL via
database()PDO wrapper, prepared statements