php composer.phar says it cannot open the input file
Could not open input file: composer.pharShort answer
The message comes from PHP, not from Composer: you asked PHP to run a file called composer.phar and it is not in the current folder. Either Composer was never downloaded there, or you are in another directory. Run the installer in the project, or install Composer globally and type composer instead.
Fix it fast
1Find out which cause you have
Check whether the file exists in the folder you are in, and which Composer, if any, is on your PATH.
ls composer.phar composer --version2Match what you see, then jump to its fix
- 1
ls says there is no composer.phar.composer.phar was never downloaded into this folderFix - 2
composer.phar exists, but not in the folder where the command runs.You are in a different directory from the one that holds composer.pharFix - 3
You typed php composer.phar from a tutorial, but Composer was installed as the composer command.You expected a global composer commandFix
- 1
What does the error look like?
Could not open input file: composer.phar
Cause 1 of 3
composer.phar was never downloaded into this folder
1Check
A local installation puts composer.phar in the directory where you run the installer. Nothing downloads it by itself.
ls -l composer.phar composer-setup.php2Fix
Run the installer from the project directory using the commands on the download page. They fetch the installer, verify its hash, run it and delete it.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
# verify the hash exactly as shown on https://getcomposer.org/download/
php composer-setup.php
php -r "unlink('composer-setup.php');"3Verify
The file exists and runs.
php composer.phar --versionConfirmed by getcomposer.org
Cause 2 of 3
You are in a different directory from the one that holds composer.phar
1Check
php composer.phar looks in the current directory. Print where you are and where the file is.
pwd
ls /path/to/where/you/installed/composer.phar2Fix
Change into that folder, or give the full or relative path to the file. Installing to another place needs --install-dir and --filename.
php /path/to/composer.phar install
# or install into a bin folder:
php composer-setup.php --install-dir=bin --filename=composer
php bin/composer --version3Verify
Composer prints its version.
php bin/composer --versionConfirmed by getcomposer.org
Cause 3 of 3
You expected a global composer command
1Check
On Windows the installer (Composer-Setup.exe) puts composer on PATH; on Linux and macOS you move the phar yourself. Open a new terminal after installing.
composer -V
where composer # Windows; use 'which composer' on Linux or macOS2Fix
Use the composer command. On Linux or macOS, move the phar onto PATH (~/.local/bin avoids sudo).
sudo mv composer.phar /usr/local/bin/composer
composer --version3Verify
composer --version works from any directory.
cd ~ && composer --versionConfirmed by getcomposer.org
How do I stop it coming back?
- Install Composer once globally and run composer, not php composer.phar.
- Do not commit composer.phar; document the global install in the project README.
- Open a new terminal after installing so the new PATH is used.
- In CI, download Composer with the documented installer commands, with the hash check.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Composer reports a different PHP version than php -v on Ubuntu
You are running 8.1.2.
Composer takes its PHP version from the interpreter that runs it, unless config.platform fakes one.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
CodeIgniter 4's file cache needs a cache directory that the web server can really write to.
2 causes, each with a fixBack end
CodeIgniter 3 loads the model but the property is undefined
The model name you are loading is the name of a resource that is already being used: user
CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.
2 causes, each with a fix