php-composer-cli
v1.0.1
Published
PHP and Composer as npm CLI package — automatically downloads PHP binaries and Composer for the current platform
Maintainers
Readme
php-composer-cli
An npm CLI package that automatically downloads PHP and Composer for your current platform and exposes them as php and composer terminal commands.
Supported platforms
| OS | Arch | PHP binary source | |---------|-------|---------------------------------------------------------------------------------------------| | Linux | x64 | crazywhalecc/static-php-cli | | Linux | arm64 | crazywhalecc/static-php-cli | | macOS | x64 | crazywhalecc/static-php-cli | | macOS | arm64 | crazywhalecc/static-php-cli | | Windows | x64 | shivammathur/php-builder-windows |
PHP version is resolved from php/php-src releases.
Composer is resolved from composer/composer releases.
Installation
Global (recommended)
npm i -g --allow-scripts=php-composer-cli php-composer-cli@latestnpm v11+: npm blocks install-time lifecycle scripts (
preinstall/install/postinstall) of registry packages by default, so they must be allowed explicitly.--allow-scripts=php-composer-cliallows this package'spostinstallscript to run and download the PHP binary +composer.pharinto the package'sdist/folder. The flag is ignored on npm < 11, so the command works there as well.
Verify that both CLIs are installed and working:
php --version && composer --versionLocal (per-project)
npm install php-composer-cli
npx php --version
npx composer --versionFor local installs, npm v11+ also skips the postinstall script by default. Add an allowScripts entry to your project's package.json and reinstall:
{
"allowScripts": {
"php-composer-cli": true
}
}Alternatively, run node node_modules/php-composer-cli/install.js once after npm install.
Usage
After a global install:
# Check versions
php --version
composer --version
# Run a PHP script
php my-script.php
# Create a new Laravel project
composer create-project laravel/laravel my-app
# Install dependencies from composer.json
composer install
# Add a package
composer require guzzlehttp/guzzleProject structure
php-composer-cli/
├── bin/
│ ├── php.js # `php` CLI wrapper
│ └── composer.js # `composer` CLI wrapper
├── dist/ # Downloaded binaries (created at install time)
│ ├── php / php.exe
│ └── composer.phar
├── lib/
│ ├── github.js # GitHub Releases API helpers
│ ├── platform.js # Platform detection + version resolution via GitHub API
│ └── download.js # HTTP download + archive extraction
├── install.js # postinstall script
└── package.jsonHow it works
npm installtriggers thepostinstallscript (install.js).- The script detects the OS and CPU architecture.
- PHP version is resolved via the GitHub Releases API of the official php/php-src repository.
- PHP binary (precompiled static executable) is downloaded from GitHub releases — no build step required:
- Windows x64: shivammathur/php-builder-windows — official prebuilt NTS ZIPs
- Linux / macOS: crazywhalecc/static-php-cli — static builds compiled from php/php-src
- Composer (
composer.phar) is downloaded from composer/composer GitHub releases — the official Composer repository. - Both are placed in
dist/. bin/php.jsandbin/composer.jsare thin wrappers that delegate all CLI arguments viachild_process.spawnSync.
Updating PHP / Composer
To force a fresh download (e.g. after a new PHP or Composer release), delete dist/ and reinstall. Locally:
rm -rf node_modules/php-composer-cli/dist
npm install
node node_modules/php-composer-cli/install.js # npm v11+ skips postinstall by defaultGlobally:
npm i -g --allow-scripts=php-composer-cli php-composer-cli@latestVersions are always resolved dynamically from GitHub — no manual edits needed.
License
MIT
