Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

php composer.phar says it cannot open the input file

ErrorCould not open input file: composer.phar

Short 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.

  • Applies to Composer 2, PHP 8.3, Windows 11, Ubuntu 24.04, macOS
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 --version
  2. 2Match what you see, then jump to its fix

    1. 1ls says there is no composer.phar.composer.phar was never downloaded into this folderFix
    2. 2composer.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. 3You typed php composer.phar from a tutorial, but Composer was installed as the composer command.You expected a global composer commandFix

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.php

2Fix

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 --version

Confirmed by getcomposer.org

Did this fix it?

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.phar

2Fix

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 --version

3Verify

Composer prints its version.

php bin/composer --version

Confirmed by getcomposer.org

Did this fix it?

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 macOS

2Fix

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 --version

3Verify

composer --version works from any directory.

cd ~ && composer --version

Confirmed by getcomposer.org

Did this fix it?

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

Back 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 fix

Back 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.