Installing Composer globally for laravel usage?

房东的猫 提交于 2019-12-10 18:04:29

问题


I'm having some trouble with installing composer globally.

I install composer into my 'C:\wamp\bin\php\php5.4.12' - directory (I'm using WAMP) and make a project in 'C:\wamp\www\project' using the command: php composer.phar create-project.

The problem is that I can only use the php composer.phar command when I'm in the directory where I installed it (bin\php\php5.4.12), this directory is already in my path variables.

Their is also a composer.bath file including in that directory: "@ECHO OFF" "php '%~dp0composer.phar' %*" that should make it global but when I use the composer command in another directory (directory of my project) using cmd, a error pops up saying:

"@ECHO OFF" "php 'C:\wamp\bin\php\php5.4.12\composer.phar... "

"@ECHO OFF" is not recognized as an internal or external command operable program or batch file.

Does anyone have a clue what the problem is?


回答1:


Locate your `php.exe file, it is probably in:

C:\wamp\bin

or

C:\wamp\bin\php

Create a file (use notepad) composer.bat in the same folder and add this line to it:

@php C:\wamp\bin\php\php5.4.12\composer.phar %*

Close and try to run composer from anywhere:

cd\
composer --version



回答2:


Although correct answer has been already posted, it is noteworthy to mention that there is a windows installer for composer https://getcomposer.org/Composer-Setup.exe

You can install it just like any other exe file. During installation it will ask for path to php.exe. It is usually located at C:\wamp\bin\php\php{php-version}\php.exe

Once installed you'll have to manually enable php_openssl, php_curl, php_socket by clicking on WAMP icon in the taskbar in bottom right. Then in PHP->PHP Extensions just click on the above three extensions to enable them.

You'll also have to enable openssl from all php.ini files by changing ;extension=php_openssl.dll to extension=php_openssl.dll i.e. uncommenting above line by removing ;

Reference: http://perials.com/install-composer-on-windows-and-wamp/




回答3:


As said here open command prompt in your windows machine, then execute the commands one by one or create a bat file and execute it. Mind your directory. Best option is :

cd C:\
mkdir ComposerSetup
cd ComposerSetup
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Now create a batch file composer.bat and paste the line in it and save:

@php C:\ComposerSetup\composer.phar %*

Now add C:\ComposerSetup as your Path environment variable. Close the promot. Open a new command prompt and type composer --v. Basically you are running the composer.bat file from your prompt now.

If you want to save the composer.phar and composer.bat file in other location, its okay, just change the directory location properly.



来源:https://stackoverflow.com/questions/21330051/installing-composer-globally-for-laravel-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!