I have just installed composer in my /usr/bin
folder, so when from that folder I run php composer.phar
I get the help info about composer. But, when I try to run the same from other folder I get Could not open input file: composer.phar
.
How to call php composer.phar
from every where without problems?
Try to run composer -V . If you get a output like Composer version followed by the version number then the composer is installed successfully. If you get any output like composer: command not found means use the following command to create a alias for the composer. So it will be executed globally.
Installation - Windows# This is the easiest way to get Composer set up on your machine. Download and run Composer-Setup.exe. It will install the latest Composer version and set up your PATH so that you can call composer from any directory in your command line. Note: Close your current terminal.
To start using Composer in your project, all you need is a composer. json file. This file describes the dependencies of your project and may contain other metadata as well. It typically should go in the top-most directory of your project/VCS repository.
I would always suggest install globally, it will be easier for you to manage, and you could easily keep it up to date.
composer.phar can be ran on its own, no need to prefix it with php
. This should solve your problem (being in the difference of bash's $PATH and php's include_path).
You can do a global installation (archived guide):
Since Composer works with the current working directory it is possible to install it in a system-wide way.
- Change into a directory in your path like
cd /usr/local/bin
- Get Composer
curl -sS https://getcomposer.org/installer | php
- Make the phar executable
chmod a+x composer.phar
- Change into a project directory
cd /path/to/my/project
- Use Composer as you normally would
composer.phar install
- Optionally you can rename the
composer.phar
tocomposer
to make it easier
Update: Sometimes you can't or don't want to download at /usr/local/bin
(some have experienced user permissions issues or restricted access), in this case, you can try this
curl -sS http://getcomposer.org/installer | php -- --filename=composer
chmod a+x composer
sudo mv composer /usr/local/bin/composer
Update 2: For Windows 10 and PHP 7 I recommend this tutorial (archived). Personally, I installed Visual C++ Redistributable for Visual Studio 2017 x64 before PHP 7.3 VC15 x64 Non Thread Safe version (check which versions of both in the PHP for Windows page, side menu). Read carefully and maybe the enable-extensions section could differ (extension=curl
instead of extension=php_curl.dll
). Works like a charm, good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With