Background
It is helpful to know that there are two ways to install (and use) Composer: locally as a file in your project directory, or globally as a system-wide executable.
Installing Composer locally simply means that you are downloading a file (composer.phar
- which is a PHP Archive) into your project directory. You will have to download it for every project that requires Composer.
Like a regular PHP file that you want to execute on the command line, you will have to run it with PHP:
php composer.phar update
Which basically tells the php
executable to run the file composer.phar
with update
as argument.
However, if you install it globally, you can make composer itself executable, so you can call it without php (and don't have to download it for every project). In other words, you can use composer like this:
composer update
Since you are executing php composer.phar update
, and you are getting the error Could not open input file: composer.phar
, you probably don't have composer.phar
in your current directory.
Solution
If you have Composer installed globally, simply run composer update
instead of php composer.phar update
.
If you don't have Composer installed yet, download the PHAR using the following command:
curl -sS https://getcomposer.org/installer | php
This will download the installer and run it using php
. The installer will download the actual Composer PHAR to your current working directory, and make it executable.
To install Composer globally (I recommend this), copy the file to a location in your PATH
. The exact location differs per operating system and setup, see https://getcomposer.org/doc/00-intro.md#globally for more information.
Personally, I prefer to install Composer in my home directory so I don't need sudo
to install or update the composer
executable (which can be a security risk). As I'm on Linux, I use the following command:
mv composer.phar ~/.local/bin/composer
alias composer="php C:\\\\Users\\\\MyUsername\\\\bin\\\\composer.phar"
to my .bashrc file. Ugly, but worked. – Tungsticsudo mv composer.phar /usr/local/bin/composer
thenalias='php /usr/local/bin/composer'
– Schumacher