Summary
Add a --system-php flag that uses the system's installed PHP binary and extensions instead of downloading static PHP builds.
Description
Currently phpx always downloads and uses static PHP binaries from static-php.dev. Some users may prefer to use their existing system PHP installation, either for:
- Using extensions already configured on their system
- Avoiding binary downloads
- Testing against their production PHP environment
- Environments where static binaries aren't available
Proposed Behavior
When --system-php is specified:
- PHP resolution: Locate PHP via
which php or PATH lookup instead of downloading static builds
- Version checking: Validate the system PHP version satisfies any
php = ">=8.2" constraint in the script metadata
- Extension checking: Verify required extensions are loaded (
php -m). If a required extension is missing, fail with a clear error - do not attempt to compile it
- Execution: Run the script using the system PHP binary
Behavior Differences
| Aspect |
Default (static PHP) |
--system-php |
| PHP binary |
Downloaded from static-php.dev |
System php in PATH |
| Extensions |
From static build tiers |
Must be pre-installed |
| Missing extension |
Compile from PECL (future) |
Error and exit |
| Version selection |
Auto-downloads matching version |
Uses whatever is installed |
Example Usage
# Use system PHP for a script
phpx run --system-php script.php
# Use system PHP for a tool
phpx tool --system-php phpstan analyse src/
# Fails if extension not available on system
phpx run --system-php script-needing-redis.php
# Error: extension 'redis' not available in system PHP
Implementation Notes
- Check
php -v output to parse version for constraint validation
- Check
php -m output to list available extensions
- Should work alongside existing
php constraint in metadata
- Consider also supporting
PHPX_SYSTEM_PHP=1 environment variable
- Could optionally support
--system-php=/path/to/php for explicit binary path
Additional Context
- This is useful for CI environments where PHP is already installed
- Allows users to leverage system-managed extensions (apt, brew, etc.)
- Provides an escape hatch when static builds don't meet requirements
Summary
Add a
--system-phpflag that uses the system's installed PHP binary and extensions instead of downloading static PHP builds.Description
Currently phpx always downloads and uses static PHP binaries from static-php.dev. Some users may prefer to use their existing system PHP installation, either for:
Proposed Behavior
When
--system-phpis specified:which phporPATHlookup instead of downloading static buildsphp = ">=8.2"constraint in the script metadataphp -m). If a required extension is missing, fail with a clear error - do not attempt to compile itBehavior Differences
--system-phpphpin PATHExample Usage
Implementation Notes
php -voutput to parse version for constraint validationphp -moutput to list available extensionsphpconstraint in metadataPHPX_SYSTEM_PHP=1environment variable--system-php=/path/to/phpfor explicit binary pathAdditional Context