Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Composer returns: "Could not open input file: composer.phar"

People also ask

How do I get a composer phar file?

phar from getcomposer.org checkbox to download a new instance of the file. The downloaded composer. phar file will be saved under the project root folder. Then, choose one of the configured local PHP interpreters from the PHP interpreter list.

What is phar in composer?

phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things. Now run php composer. phar in order to run Composer.


If you followed instructions like these:

https://getcomposer.org/doc/00-intro.md

Which tell you to do the following:

$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer

Then it's likely that you, like me, ran those commands and didn't read the next part of the page telling you to stop referring to composer.phar by its full name and abbreviate it as an executable (that you just renamed with the mv command). So this:

$ php composer.phar update friendsofsymfony/elastica-bundle

Becomes this:

$ composer update friendsofsymfony/elastica-bundle

I had the same problem on Windows and used a different solution. I used the Composer_Setup.exe installation file supplied by the composer website and it does a global install.

After installing, make sure your PATH variable points to the directory where composer.phar is stored. This is usually C:\ProgramData\ComposerSetup\bin (ProgramData might be a hidden directory). It goes without saying, but also be sure that the PHP executable is also in your PATH variable.

You can then simply call

composer install

instead of

php composer.phar install

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

If anyone else came this low on the page and still didn't find a working answer (like I did), use this:

$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer.phar
$ alias composer='/usr/local/bin/composer.phar'
$ composer --version

et voila! A working composer :-)