How to run composer from anywhere?
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?
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
- Open terminal
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!
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).