257

I am new to symfony2 and reading symblog. In third chapter while trying with data-fixtures I tried the command:

php composer.phar update

but I got the error:

Could not open input file: composer.phar

So I googled a little and tried

php composer.phar install

but still getting the same error. So please guide how to deal with this composer to install new extentions or bundles like data-fixtures in symfony2 using wamp.

Nic Wortel
  • 11,155
  • 6
  • 60
  • 79
user3291745
  • 2,629
  • 2
  • 12
  • 8
  • did you install composer.phar in right place?? – hizbul25 Feb 10 '14 at 06:53
  • I had this issue while trying to setup composer globally. I ended up adding `alias composer="php C:\\\\Users\\\\MyUsername\\\\bin\\\\composer.phar"` to my *.bashrc* file. Ugly, but worked. – Batandwa Jun 04 '14 at 11:17
  • 23
    Solution for windows user is below by @Jamil, you have to user **composer** rather than **php composer.phar** – Carlos487 Oct 08 '15 at 20:43
  • You don't no need .phar if you have already installed composer just run composer update – meddy Feb 13 '18 at 10:07

41 Answers41

324

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
Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
  • 42
    The thing to remember is that if you installed it correctly (on Windows) and added it to your environment's PATH variable then you do not need to type php composer.phar and use composer instead. – AturSams Jul 08 '14 at 11:57
  • @Chris Moschini Seems you can help me. Look at this : https://stackoverflow.com/questions/52091827/how-can-i-require-composer-autoloader-in-the-laravel – moses toh Aug 30 '18 at 07:53
  • do we have to install composer in each project , I installed the composer using their installer – Sushant Bhargav Sep 28 '18 at 08:51
177

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
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
The Unknown Dev
  • 3,039
  • 4
  • 27
  • 39
  • 7
    This finally works, I don't understand why I can't find this info anywhere on the composer website ... . – herrfischer Mar 10 '16 at 08:16
  • 4
    Thank you! That is not mentioned in the "basic usage" section in the Composer docs.. https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies – Nick Rolando Jan 11 '17 at 22:41
  • It's been over two years since this answer, and the docs still haven't been updated, so I had the same problem. Thanks! – Kelderic May 21 '19 at 12:58
118

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
Nic Wortel
  • 11,155
  • 6
  • 60
  • 79
  • 1
    I wish I could update this answer more than once. Besides answering the question, it clarifies the question of the difference between local and global installation of Composer. Thank you for this. – NaijaProgrammer Dec 12 '18 at 12:42
68

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 :-)

Stan Smulders
  • 6,079
  • 1
  • 27
  • 23
  • Thank you, Agent Smulders. ;) – Steven Ventimiglia Jan 17 '17 at 19:42
  • Worked for me, but I had to change one line so that it would work properly $alias composer='/usr/local/bin/composer' – Steph Moreau Feb 23 '17 at 21:08
  • On my Mac OS X I added the alias command to my .bash_profile. This will make the alias persistent for new terminal sessions. – noctufaber May 09 '17 at 20:13
  • 1
    The second line does not work `mv composer.phar /usr/local/bin/composer.phar`. I get an error: `mv: regular File '/usr/local/bin/composer.phar'` could not be installed: missing rights. – Peter Jan 25 '18 at 08:42
  • @Peter I got missing rights as well while trying the command in integrated VS Code Terminal. Instead I opened Git Bash (or any terminal you use) **as Administrator** and all commands worked properly. – s3c Nov 16 '20 at 09:07
  • after tons of attempts, finally this worked for me. Thanks buddy – Rohit Jun 29 '23 at 14:26
16

To solve this issue the first thing you need to do is to get the last version of composer :

curl -sS https://getcomposer.org/installer | php

I recommend you to move the composer.phar file to a global “bin” directoy, in my case (OS X) the path is:

mv composer.phar /usr/local/bin/composer.phar

than you need to create an alias file for an easy access

alias composer='/usr/local/bin/composer.phar'

If everything is ok, now it is time to verify our Composer version:

composer --version

Let's make composer great again.

Script47
  • 14,230
  • 4
  • 45
  • 66
Achref Gassoumi
  • 1,035
  • 10
  • 20
15

I found this worked as I did not have curl installed. On Windows 8 with XAMPP installed. It will add it to your local build I use .gitignore to avoid the repo

php -r "readfile('https://getcomposer.org/installer');" | php

I got it from here: https://getcomposer.org/download/

purencool
  • 423
  • 7
  • 17
11

This worked for me:

composer install

Without

php composer install
Monasha
  • 711
  • 2
  • 16
  • 27
Mohamed Fanane
  • 171
  • 2
  • 2
  • even without extension? Also, please add 4 spaces indetation to your code lines so that they are formatted as code – YakovL Aug 10 '16 at 15:30
10

Run the following in command line:
curl -sS https://getcomposer.org/installer | php

5

Yesterday I was trying to install Yii2 framework on Windows 10 and I have same problem(Could not open input file: composer.phar) running this command:

php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9

Issue is composer.phr file is not in current directory,you need to give full path composer.phr like

php C:\ProgramData\Composer\bin\composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9

Or you can create yii2 project using this command:

 composer create-project yiisoft/yii2-app-advanced advanced 2.0.9

Or

composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9
Muhammad Shahzad
  • 9,340
  • 21
  • 86
  • 130
3

I had the same issue. It is solved when I made composer globally available. Now I am able to tun the commands from any where in the folder.

composer update

composer require "samplelibraryyouwant"

Kiren S
  • 3,037
  • 7
  • 41
  • 69
  • 3
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Niki van Stein Oct 30 '15 at 12:36
  • @BasvanStein It does seem like an attempt to answer. If you think this answer is wrong, then you can downvote it. – Artjom B. Oct 31 '15 at 17:54
3

Use this :

php -r "readfile('https://getcomposer.org/installer');" | php
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
3

Hi friends, follow the steps to fix this issue in MAC OS

  • Step 1: first run the command in Terminal with your project directory

    $ curl -sS https://getcomposer.org/installer | php

  • Step 2: Move the composer.phar in your project directory

    $ mv composer.phar /Applications/MAMP/htdocs/bashrushAPI/composer.phar

  • Step 3: Setup alias the composer

    $ alias composer='/Applications/MAMP/htdocs/bashrushAPI/composer.phar'

  • Step 4: Check the composer version now

    $ composer --version

    Composer version 1.7.2 2018-08-16 16:57:12

  • Step 5: Confirm the project folders and file placed on bellow

    $ ls

    CONTRIBUTING.md docker-compose.yml templates README.md logs tests composer.json phpunit.xml vendor composer.lock public composer.phar src

  • Step 6: Now update composer

    $ composer.phar update

    Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files

  • Step 7: Run your sample project

    $ php composer.phar start

    php -S localhost:8080 -t public [Thu Sep 27 03:16:11 2018] ::1:51177 [200]: / [Thu Sep 27 03:16:11 2018] ::1:51178 [404]: /favicon.ico - No such file or directory

Murugan Vadivel
  • 119
  • 1
  • 1
  • 5
2

Easy answer, navigate to the directory where you already have the composer.json file that you want to run (ideally your project folder) then download composer into the same folder, then instantly run the install command like so:

 php composer.phar install

This will automatically find the composer.json and run your required scripts. Good luck. This stuff is a breeze for terminal wizards and totally bizarre to the rest of us

Chris Klingler
  • 5,258
  • 2
  • 37
  • 43
2

I am using windows 8.0. In my case to install or update i just use composer install or something else instead of php composer.phar. This worked for me like

composer require google/apiclient:1.*
bicky
  • 51
  • 5
2

To googlers who installed composer via HomeBrew: make a symbolic link for /usr/local/bin/composer

ln -s /usr/local/bin/composer /usr/local/bin/composer.phar
0xKayvan
  • 368
  • 1
  • 4
  • 18
2

I got this error "Could not open input file: composer.phar" while installing Yii2 using below mentioned command.

php composer.phar create-project yiisoft/yii2-app-basic basic

Solutions which worked for me was, I changed the command to

composer create-project yiisoft/yii2-app-basic basic

I hope it help!

2

If you are using Ubuntu/Linux and you are trying to run

php composer.phar require intervention/image on your command line.

Use sudo composer require intervention/image instead. This will give you want you are looking for.

Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
1

enter image description here

your composer.phar should be placed in above way.

hizbul25
  • 3,829
  • 4
  • 26
  • 39
  • I am using windows8 and installed exe of composer as on https://getcomposer.org/download/. Then I copied the composer.phar file to my project as per the structure shown by you. composer.json and composer.lock files were already there as it was default symfony package download. After doing this when I run composer udpate command, it took around half an hour but not completed yet. What's wrong? Please suggest. Thanks in advance! – user3291745 Feb 10 '14 at 07:27
  • ok, do you use cmd for command? so you should change directory right way. Better provide your directory structure with screen shot. – hizbul25 Feb 10 '14 at 07:32
  • Stackoverflow do not allows me to upload image as I am just new born user with less points or reputation. I am running composer update command in C:\wamp\www\Symfony\ directory and in that directory I can see composer.phar, composer.json, composer.lock folders app, bin, vendor, src and web. – user3291745 Feb 10 '14 at 07:41
  • C: cd wamp\www\Symfony – hizbul25 Feb 10 '14 at 07:55
  • in this regard developer always suggest linux for php/python/ruby. :) – hizbul25 Feb 10 '14 at 07:57
1

For windows, I made composer.cmd and used the below text:

php c:\programs\php\composer.phar %*

where composer.phar is installed and c:\programs\php\ is added to my path.

Not sure why this isn't done automatically.

TamusJRoyce
  • 817
  • 1
  • 12
  • 25
1

For Windows10 Pro, Following steps fix the issue. select properties check the Unblock program option. run the installer, run the command CMD with Admin rights. At command promp run composer --version to make sure it is globally installed. you should be able to now run composer require drush/drush This is for drush dependency using composer.

Narayan P
  • 139
  • 1
  • 3
1

Command like this :

composer.phar require intervention/image

error: composer.phar: command not found

I solved the problem by following this process

i set the composer globally and renamed composer.phar to composer then run this command composer require intervention/image . and now it's working fine

Mamunur Rashid
  • 186
  • 2
  • 11
1

Just open cmd as Administrator and go into your project folder and check it is working or not using composer command.

The above error is because of the composer is not accessible globally. So you need to run "cmd" as Administrator.

This is working fine for me.

1

I had an issue getting a package.json's script to run composer dumpautoload.

I had the file /usr/local/bin/composer.phar, and also the file ~/.bash_profile (on OSX) contained:

alias composer="php /usr/local/bin/composer.phar"

This allowed composer to work from the command line, but it didn't allow scripts to execute composer.

The fix was this:

$ cd /usr/local/bin
$ mv composer.phar composer
$ sudo chmod +x composer // +x allows the file to be executable, such as by CLI scripts

But that yielded this error Could not open input file: /usr/local/bin/composer.phar

The fix was to update ~/.bash_profile (sudo nano ~/.bash_profile), and change the composer alias to:

alias composer="php /usr/local/bin/composer"

# ie: `.phar` extension removed

Now everything is behaving as expected.

agm1984
  • 15,500
  • 6
  • 89
  • 113
0

Your composer.phar must be in Source files. I had same problem and I just cut my composer.phar into mine framework-standard-edition folder, where is my whole strong textproject.

Lackeeee
  • 459
  • 1
  • 8
  • 13
0

if the composer is already install all you need is to know where the composer.phar file is (its directory) after that you move to your symfony project where you have the composer.json and from that directory you execute your composer.phar file. In windows here is what you have to do.

symfony project directory_where_composer.json_is>php the_directory_where_composer.phar_is/composer update 

That's all

aidonsnous
  • 1,475
  • 4
  • 19
  • 41
0

use two steps .

curl -sS https://getcomposer.org/installer | php

sudo php composer.phar update

Mathesh Raj
  • 671
  • 6
  • 15
0

You can do

curl -sS https://getcomposer.org/installer | php

The -sS flag meaning don't show progress, do show errors

and then

php composer.phar install

from: How do I get cURL to not show the progress bar?

https://packagist.org/

Community
  • 1
  • 1
Kyrre
  • 670
  • 1
  • 5
  • 19
0

I've reach to this problem when trying to install composer on a Window 7 machine from http://getcomposer.org/download page. As there was an existing compose version (provided by acquia Dev Desktop tool) the installation fails and the only chance was to fix this issue manually. (or to remove Dev Desktop tool composer).

Anyway the error message is quite straightforward (Could not open input file: composer.phar), we should then tell the system where the file is located.

Edit composer.bat file and should look like:

@SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;%PATH%
php.exe composer.phar %*

See that composer.phar doesn´t have a file path. When standing in a different folder than the one where composer.phar is located the system won´t be able to find it. So, just complete the composer.phar file path:

@SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;;%PATH%
SET composerScript=composer.phar
php.exe "%~dp0%composerScript%" %*

Reopen your window console and that should do the trick.

EDIT: this has an issue because it always uses %~dp0%composerScript% folder as composer execution. Then all configurations are done in that folder (besides standing on your current project folder) and not in your project folder.

So far I haven't found a was to make a manual composer installation to work globally on Windows. Perhaps you should go ahead with composer for windows installation mentioned above.

mariano_c
  • 371
  • 2
  • 9
0

Do not access the composer by composer composer.pher install

use composer install

abey
  • 11
0

You can just try this command if you're already installed the Composer :

composer update 

or if you want add some bundle to your composer try this :

composer require "/../"
jabir
  • 1
0

use composer alone without php

like :

composer create-project --prefer-dist --stability=dev developeruz/yii-vue-app basic
mohammad nazari
  • 951
  • 8
  • 11
0

I have fixed the same issue with below steps

  1. Open project directory Using Terminal (which you are using i.e. mintty )
  2. Now install composer within this directory as per given directions on https://getcomposer.org/download/

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('SHA384', 'composer-setup.php') === 'the-provided-hash-code') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php php -r "unlink('composer-setup.php');"

  1. Now run your command.

Everything is working fine now because the composer.phar file is available within the current project directory.

thanks

Anoop Saini
  • 307
  • 3
  • 5
0

With me it works just you need the file composer.phar and composer.json in the current project. The command is

php composer.phar update 
Stefan
  • 8,819
  • 10
  • 42
  • 68
0

I know that maybe my answer is too specific for a embedded QNAP server, but I ended here trying to install Yii:

For me, inside a QNAP NAS through PuTTY, after trying all tricks above, and updating PATH to no avail, the only cmd line that works is:

 /mnt/ext/opt/apache/bin/php /usr/local/bin/composer create-project yiisoft/yii2-app-basic basic

Of course, adapt your path accordingly...

If I do a which composer, I have a correct answer, but if I do a which php nothing returns.

Besides that, trying to run

/mnt/ext/opt/apache/bin/php composer create-project yiisoft/yii2-app-basic basic

or referring to

composer.phar

didn't worked too...

0

the simple straight way i went about this similar was - navigate to my project folder using cd command prompt - type in composer inside cdm to be sure its installed - if yes then type composer require ../the extension u intended to install

0

IF want to create composer.phar file in any folder follow this command.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === 'c5b9b6d368201a9db6f74e2611495f369991b72d9c8cbd3ffbc63edff210eb73d46ffbfce88669ad33695ef77dc76976') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"
Regolith
  • 2,944
  • 9
  • 33
  • 50
0

I have been facing the same issue till I used the following command.

composer self-update

Hope this works for you too!

If not, You can check on the entire release here https://blog.packagist.com/composer-2-0-is-now-available/

Desire Kaleba
  • 1,264
  • 11
  • 11
0

This is very easy, just run without the 'PHP' prefix.

composer.phar update

This should work.

0

for windows :)

composer update
composer self-update 

you'd been asked for user permission,

and one more command:

composer require that_extention_you_want 

(instead of your first one: php composer.phar that_extention_you_want)

CodeToLife
  • 3,672
  • 2
  • 41
  • 29
0

I also face this problem.

when I use to run this command

php composer.phar require intervention/image

Could not open input file: composer.phar

then I solve this problem just run this command: -> composer.phar require intervention/image

so open your project and open git bash or cmd

and remove php and run just this command :-> composer.phar update or composer.phar install

Thank you

Meheraz
  • 41
  • 2
0

enter image description here

Windows 10 :

  1. Make sure installed PHP

  2. XAMPP or other

  3. Open XAMPP Control Panel, then open Shell

  4. type ;

    curl -sS https://getcomposer.org/installer | php

  5. Then ;

    php composer.phar