Skip to content

feat(php): add --system-php flag to use locally installed PHP #3

Description

@eddmann

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:

  1. PHP resolution: Locate PHP via which php or PATH lookup instead of downloading static builds
  2. Version checking: Validate the system PHP version satisfies any php = ">=8.2" constraint in the script metadata
  3. 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
  4. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions