fzb 2018-05-27 22:41:32 6537次浏览 3条评论 3 6 0

我电脑安装的是 php环境 因为我需要安装yii框架 所以研究了一下安装composer

我的php 安装目录是 e:/wamp64/bin/php/php7.0.10

安装composer前必须把php安装目录加入到系统变量 怎么把e:/wamp64/bin/php/php7.0.10该路径加入到系统变量

请看这一篇文章介绍

php -v 可以测试出你的php安装目录是否已经加入了环境变量

C:\Users\fengz>php -v
PHP 7.0.10 (cli) (built: Aug 18 2016 09:48:53) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies`

能够看到php版本号 说明你已经加入了,否该提示 “php不是内部命令”

我是使用命令行安装composer的 命令如下:

先cmd命令行模式里 下载 composer.phar 文件

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

执行完成 把下载下来的 composer.phar 文件 剪切到 e:/wamp64/bin/php/php7.0.10 目录下

E:/wamp64/bin/php/php7.0.10> echo @php "%~dp0composer.phar" %*>composer.bat

执行完成 测试composer是否安装成功

cmd 命令行输入 composer -V

C:\Users\fengz>composer -V
Composer version 1.6.5 2018-05-04 11:44:59

继续 继续 安装 yii2 advanced

安装前

//将Composer更新站点替换为中国全量镜像

e:\wamp64\www>composer config -g repo.packagist composer https://packagist.phpcomposer.com

//设置完成,你就可以使用composer进行Yii2的安装了

安装yii2 必须安装 Composer Asset插件

php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"

这个 ^ 符合是表示版本号高于等于1.2.0

Changed current directory to C:/Users/User/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing fxp/composer-asset-plugin (v1.2.0)
    Downloading: 100%
Writing lock file
Generating autoload files

表示Composer Asset插件安装完成继续

e:\wamp64\www> composer create-project yiisoft/yii2-app-advanced advanced ^2

安装过程中提示需要输入 token 这个是什么鬼呢 ?不要急,这是因为yii2有些代码是在github上,
提示这个就到github创建一个

进入 https://github.com/settings/tokens 点击 「Generate new token」 新建一个 Token,选择默认新建就行,然后就会得到一个 Token,然后输入这个值就 OK 了。

这个token在cmd命令行只能输入,输入的时候看不到是隐藏的
输入完 回车 等待.....

Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing yiisoft/yii2-composer (2.0.4)
    Downloading: 100%

  - Installing bower-asset/jquery (2.2.3)
    Downloading: 100%

  - Installing bower-asset/yii2-pjax (v2.0.6)
    Downloading: 100%

  - Installing letyii/yii2-rbac-mongodb (dev-master 1f17c4e)
    Cloning 1f17c4ea8e5de189a5c8df668de01e3130995e3e

  - Installing swiftmailer/swiftmailer (v5.4.1)
    Downloading: 100%

  - Installing yiisoft/yii2-swiftmailer (2.0.5)
    Downloading: 100%

  - Installing yiisoft/yii2-mongodb (2.0.4)
    Downloading: 100%

  - Installing mdmsoft/yii2-admin (2.6)
    Downloading: 100%

  - Installing imagine/imagine (v0.5.0)
    Downloading: 100%

  - Installing yiisoft/yii2-imagine (2.0.3)
    Downloading: 100%

  - Installing raoul2000/yii2-workflow (1.0.0)
    Downloading: 100%

  - Installing yiisoft/yii2-codeception (2.0.5)
    Downloading: 100%

  - Installing bower-asset/bootstrap (v3.3.5)
    Downloading: 100%

  - Installing yiisoft/yii2-bootstrap (2.0.6)
    Downloading: 100%

  - Installing yiisoft/yii2-debug (2.0.6)
    Downloading: 100%

  - Installing bower-asset/typeahead.js (v0.11.1)
    Downloading: 100%

  - Installing phpspec/php-diff (v1.1.0)
    Downloading: 100%

  - Installing yiisoft/yii2-gii (2.0.5)
    Downloading: 100%

  - Installing fzaninotto/faker (v1.5.0)
    Downloading: 100%

  - Installing yiisoft/yii2-faker (2.0.3)
    Downloading: 100%

Writing lock file
Generating autoload files

大功告成 进入 e:\wamp64\www 目录即可看到安装好的项目
可以开始研究学习yii2 啦

觉得很赞
  • 评论于 2018-06-13 23:08 举报

    很好,整理得非常好。

  • 评论于 2018-07-10 14:58 举报

    补充一下 :
    如果出现
    Could not open input file: composer.phar
    的情况,可以选择输入下面的代码:
    composer global require "fxp/composer-asset-plugin:^1.2.0"

  • 评论于 2021-03-22 17:35 举报

    php.png
    composer.png
    版本1.2.png
    为什么我的这个老是报版本这个错误?换了版本号也是这样的

您需要登录后才可以评论。登录 | 立即注册