php 如何在 Windows 中安装依赖项或完全使用 Composer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20115757/
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-08-25 02:53:46  来源:igfitidea点击:

how to install dependencies or use composer at all in windows

phpcomposer-phpphar

提问by user2167582

I've installed composer via windows installer, and set the correct path variables for php to wamp's php, now I created a composer.json( and later .phar) file

我已经通过 Windows 安装程序安装了 Composer,并将 php 的正确路径变量设置为 wamp 的 php,现在我创建了一个 composer.json(以及后来的 .phar)文件

and attempt to install dependencies listed there

并尝试安装那里列出的依赖项

{
"name": "phpunit/php-unit",
"require": {
    "php": ">5.4.12",
    "phpunit/phpunit": "3.7.28"
}
}

this comes out of almost every command, including

这几乎来自每个命令,包括

php composer.phar install
php composer.json install

i did ran this in windows cmd so im not sure if that affects anything.

我确实在 Windows cmd 中运行过这个,所以我不确定这是否会影响任何事情。

回答by Girish Thimmegowda

For very Beginner Windows Users

对于非常初级的 Windows 用户

  1. Download the installer for windows from here

  2. Check the installation by executing composercommand at command prompt

  3. Now, create the composer.jsonfile at the same level where you have Vendordirectory (not inside Vendor).

  4. Move to the directory where you have composer.jsonwith the command prompt and run the following command:

    composer install
    
  5. It will show messages like 'packages are downloaded' and 'autoload.php file created'. (Check your /app/Vendor/directory)

  6. Now insert this code at the beginning of /app/config/core.php:

    require_once dirname(__DIR__) . '/Vendor/autoload.php';
    
  1. 这里下载 windows 安装程序

  2. 通过composer在命令提示符下执行命令来检查安装

  3. 现在,composer.json在您拥有Vendor目录(不是 inside Vendor)的同一级别创建文件。

  4. 移动到composer.json命令提示符所在的目录并运行以下命令:

    composer install
    
  5. 它将显示诸如“包已下载”和“autoload.php 文件已创建”之类的消息。(检查你的/app/Vendor/目录)

  6. 现在在开头插入此代码/app/config/core.php

    require_once dirname(__DIR__) . '/Vendor/autoload.php';
    

The code above will load all the classes automatically.

上面的代码将自动加载所有类。

Hope this helps for beginners.

希望这对初学者有所帮助。

回答by Girish Thimmegowda

Edit: actually there is a Windows installer on the Composer download pagethat will install Composer globally, so you won't need any composer.pharanymore. Install it from here, and then just run "composer install" from the directory where you have your composer.json.

编辑:实际上 Composer下载页面上有一个 Windows 安装程序,可以全局安装 Composer,因此您不再需要任何安装程序composer.phar。从这里安装它,然后从您拥有composer.json.

(original answer below)

(以下原答案)

I didn't test this myself, but I think it's how it should work :

我自己没有测试过,但我认为它应该如何工作:

Download the composer.pharand put it in the same directory as your composer.json.

下载composer.phar并将其放在与composer.json.

cdinto the directory where you have your composer.json:

cd进入您拥有以下内容的目录composer.json

cd some\directory

cd 一些\目录

Finally, run the composer :

最后,运行 composer :

php composer.phar install

php composer.phar 安装

回答by Mohammad H.

I have this problem for a long time but with a simple mistake Okay First need to enable extension=php_openssl.dllon your php.ini and if it does not exist , so enable or add in to end of file second step go to this directory :

我有这个问题很长时间了,但有一个简单的错误 好的 首先需要extension=php_openssl.dll在您的 php.ini上启用,如果它不存在,那么启用或添加到文件末尾第二步转到此目录:

C:\Users\{YOUR USERNAME}\AppData\Roaming\Composer

And paste your composer.json to here , make a folder to sure and name it that "vendor" , then enable or run your PHP server and run cmdas administrator and type this

并将您的 composer.json 粘贴到此处,确保创建一个文件夹并将其命名为“供应商”,然后启用或运行您的 PHP 服务器并以管理员身份运行cmd并键入此内容

composer install

Enjoy It

好好享受