How to run composer from anywhere?

前端 未结 10 1469
名媛妹妹
名媛妹妹 2020-12-04 07:51

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, whe

10条回答
  •  一整个雨季
    2020-12-04 07:57

    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.

    1. Change into a directory in your path like cd /usr/local/bin
    2. Get Composer curl -sS https://getcomposer.org/installer | php
    3. Make the phar executable chmod a+x composer.phar
    4. Change into a project directory cd /path/to/my/project
    5. Use Composer as you normally would composer.phar install
    6. Optionally you can rename the composer.phar to composer 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

    1. Open terminal
    2. curl -sS http://getcomposer.org/installer | php -- --filename=composer
    3. chmod a+x composer
    4. sudo mv composer /usr/local/bin/composer

    Update 2: For Windows 10 and PHP 7 I recommend this tutorial. 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!

提交回复
热议问题