为 Laravel 使用全局安装 Composer?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21330051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:54:22  来源:igfitidea点击:

Installing Composer globally for laravel usage?

phplaravelinstallationglobalcomposer-php

提问by user3231419

I'm having some trouble with installing composer globally.

我在全局安装 Composer 时遇到了一些问题。

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.

我安装作曲家为我的'C:\ WAMP \ BIN \ PHP \ php5.4.12' -目录(我使用WAMP),并在项目'C:\ WAMP \ WWW \项目'使用下面的命令:php composer.phar create-project

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

问题是我只能php composer.phar在我安装它的目录(bin\php\php5.4.12)中使用该命令,这个目录已经在我的路径变量中了。

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:

他们也是一个 composer.bath 文件,包括在该目录中:"@ECHO OFF" "php '%~dp0composer.phar' %*"这应该使它成为全局文件,但是当我在另一个目录(我的项目目录)中使用 composer 命令时cmd,会弹出一个错误说:

"@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.

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

“@ECHO OFF”不是内部或外部命令可操作的程序或批处理文件。

Does anyone have a clue what the problem is?

有谁知道问题是什么?

回答by Antonio Carlos Ribeiro

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

找到你的 `php.exe 文件,它可能在:

C:\wamp\bin

or

C:\wamp\bin\php

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

composer.bat在同一个文件夹中创建一个文件(使用记事本)并向其中添加以下行:

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

Close and try to run composer from anywhere:

关闭并尝试从任何地方运行 composer:

cd\
composer --version

回答by Suraj

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

虽然已经发布了正确答案,但值得注意的是,这里有一个用于 Composer https://getcomposer.org/Composer-Setup.exe的 Windows 安装程序

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

您可以像安装任何其他 exe 文件一样安装它。在安装过程中,它会询问 php.exe 的路径。它通常位于 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.

安装后,您必须通过单击右下角任务栏中的 WAMP 图标手动启用 php_openssl、php_curl、php_socket。然后在 PHP->PHP Extensions 中点击以上三个扩展来启用它们。

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 ;

您还必须通过将 ;extension=php_openssl.dll 更改为 extension=php_openssl.dll 来启用所有 php.ini 文件中的 openssl,即通过删除 ;

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

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

回答by aniruddha

As said hereopen 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 :

正如这里所说在你的windows机器上打开命令提示符,然后一一执行命令或创建一个bat文件并执行它。注意你的目录。最佳选择是:

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:

现在创建一个批处理文件 composer.bat 并将该行粘贴到其中并保存:

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

现在添加 C:\ComposerSetup 作为您的 Path 环境变量。关闭促销。打开一个新的命令提示符并键入 composer --v。基本上,您现在正在从提示符运行 composer.bat 文件。

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

如果你想把 composer.phar 和 composer.bat 文件保存在其他位置,也可以,只要适当改变目录位置即可。