小马哥 2014-12-28 17:01:17 182529次浏览 68条评论 49 15 0

这些天看了一下,发现还有很多人对 Yii2 安装存在许多问题,在网上搜了很多资料,才发现他们都很不全面,以至于走了很多弯路,
下面我把完整的安装流程介绍给大家:按照这个流程走,相信你一定可以成功!
总感觉这个教程排版都很靠左,感觉这个样式排版不好的话,可以去我的博客看:http://happymc.iteye.com/blog/2150829
希望对你们有帮助!

前提:非常重要,你的php版本必须是php5.4以上

1.首先需要下载应用模板,分为基础模板和高级应用模板,这里我以高级应用模板为例子 :
去这里现在高级应用模板 https://github.com/yiisoft/yii2-app-advanced

2.下载完之后解压放在www目录我是放在 D:\wamp\www\yii2\advanced

cmd dos命令进入这个D:\wamp\www\yii2\advanced下:
输入图片说明

3.运行 php -r "readfile('https://getcomposer.org/installer');" | php
输入图片说明

4.这是就在D:\wamp\www\yii2\advanced目录下面下载了一个composer.phar文件,有了这个文件就可以执行php composer.phar命令了,提示:
输入图片说明

5.准备所有插件!!非常重要,少了这步一切都会失败 (记得配置php环境变量啊)
执行命令:php composer.phar global require "fxp/composer-asset-plugin:1.0.0"
输入图片说明

6.安装我们的yii2的应用:
执行命令:php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced ../yii2test 就会在上一层目录下生成yii2test应用 。
请注意,到第六步很可能就一直停在那里了,这个时候,登录GitHub的用户名和密码没有就注册个账号,退出cmd,重新执行第6步可。
若提示安装过程中输入你的 GitHub 的用户名和密码。那就输入它们并继续即可。现在可能是输入token了
输入图片说明

7.最后一步:初始化我们的应用,初始化是在你创建的yii2test目录下 执行cmd init命令 选0 y
输入图片说明

ok,这么我们的yii2的安装就完成了,进入测试目录:
localhost/yii2/yii2test/frontend/web/index.php

会看到如下界面:
输入图片说明

这就表明的你的yii2安装成功了,一定要记住你的php版本是php5.4以上的!

觉得很赞
  • 评论于 2014-12-28 23:01 举报

    写的不错,对新手很有帮助,赞一个!

    5 条回复
    评论于 2014-12-29 10:07 回复

    我也是从新手来过,很理解新手学yii的苦楚啊

    评论于 2015-07-08 17:59 回复

    这个可以让人少走一点弯路,鉴于现在学习成本比以前成本高了不少。

    评论于 2015-10-17 17:43 回复

    请问这个token 那儿来的啊

    评论于 2015-10-22 23:03 回复

    没人回答呢,我说下吧,注册github账户,然后在“个人中心”->“Settings”->"Personal access tokens"中来生成个token就行了。

    评论于 2016-09-08 10:10 回复

    注册github账户,然后在“个人中心”->Personal access tokens 来生成token 是正解

    觉得很赞
  • 评论于 2014-12-29 09:23 举报

    第五步 报 Nothing to install or update

    1 条回复
    评论于 2015-01-03 21:30 回复

    提示这个命令可以跳过这个步骤的,不需要更新了就

    觉得很赞
  • 评论于 2015-01-04 09:39 举报

    写的不错,对舰长很有帮助

  • 评论于 2015-01-04 10:50 举报

    呼叫作者,呼叫作者,文档很给力,但是到第六步的时候,提示输入用户名和密码,那么问题来了,不输可以吗?如果可以怎么进行下一步?我到githu注册了账号,然后一直提示我输入账号密码,一直循环咋回事儿?想上传本地图片的,不会上传

    5 条回复
    评论于 2015-01-04 11:07 回复

    这步是正常的,输入自己正确的git账号就可以了

    评论于 2015-01-04 12:40 回复

    @小马哥: 退出重输cmd,安装成功,嘿嘿

    评论于 2015-01-04 17:27 回复

    @YiiSoEasy: 呵呵,是的 啊,我当时安装的时候,没安装git,下载完了,安装就是不成功,就是没退出cmd的原因啊

    评论于 2015-01-04 17:48 回复

    @YiiSoEasy: 现在这个文档很完整了,我更新了

    评论于 2017-03-11 11:16 回复

    层主问题解决了吗,我也是这个问题

  • 评论于 2015-01-04 13:19 举报

    composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced ../yii2test在这一步的时候报

    could not open input file:composer怎么弄呀,急等

    2 条回复
    评论于 2015-01-04 17:29 回复

    这个是你的composer.phar,没在你的目录下,执行这个命令的时候,cmd进入的目录一定要有这个文件的,请细看第4步

    评论于 2015-01-05 09:08 回复

    @小马哥: 解决啦,谢谢。我还是小白

    觉得很赞
  • 评论于 2015-01-04 13:48 举报

    还有GitHub 的用户名和密码是什么呀

    1 条回复
    评论于 2015-01-04 17:29 回复

    因为你安装的数据是在git上面获取的,所有安装的时候会需要你输入git账号的

  • 评论于 2015-01-19 14:19 举报

    我执行第三步有问题呀!请帮忙解决

    1 条回复
    评论于 2015-01-21 09:16 回复

    其实第三步主要是下载composer.phar这个文件的,你可能是网速慢下载不动,你也可以直接百度下载这个文件,因为有了这个文件才可以执行php composer.phar命令,或者你看看你的目录结构是否一致

  • 评论于 2015-02-10 02:34 举报
    Warning: require(F:\Web\website\test_yii\basic\frontend\web/../../vendor/autoload.php): failed to open stream: No such file or directory in F:\Web\website\test_yii\basic\frontend\web\index.php on line 5
    Call Stack
    
    Fatal error: require(): Failed opening required 'F:\Web\website\test_yii\basic\frontend\web/../../vendor/autoload.php' (include_path='.;C:\php\pear') in F:\Web\website\test_yii\basic\frontend\web\index.php on line 5
    

    求解。。。

    9 条回复
    评论于 2015-02-10 09:22 回复

    应该是你的目录路径不对,安装的时候需要在项目根目录下进行,自己试着研究一下,提升提升自己

    评论于 2015-02-12 10:01 回复

    composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced ../yii2test
    这一步出错!安装还没完全,还有东西没download下来,删除yii2test文件夹 重新执行 最后重新Generating autoload files
    方算完全

    评论于 2015-03-14 15:49 回复

    @sanxianlee: 非常抱歉现在文档已更新完整,还有东西没更新下来的原因是没有运行第6步,sorry
    第6步已经更新

    评论于 2015-04-24 10:35 回复

    我也遇到了这个问题,怎么解决呀

    评论于 2016-04-25 22:32 回复

    很简单,用新的安装命令就可以了

    composer global require "fxp/composer-asset-plugin:~1.1.1"
    composer create-project --prefer-dist yiisoft/yii2-app-basic basic
    
    评论于 2017-03-11 14:55 回复

    我也遇到和层主一样的问题,有解决办法了吗??

    评论于 2017-04-26 22:31 回复

    apache出错,重装Apache问题就解决了

    评论于 2017-04-26 22:56 回复

    F:\Web\website\test_yii\basic\frontend\web\index.php on line 5 这句出错就是Apache服务器不允许执行 require(__DIR__ . '/../../vendor/autoload.php'); 其实也就是不允许执行require这句,apache配置文件。xx.com.conf中是否是这样的?php_admin_value open_basedir "/home/www/xx.com/frontend/web:/tmp/:/var/tmp/:/proc/" ?如果是,恭喜你,原因找到了,这里限定了打开目录仅限于web目录,改成 php_admin_value open_basedir "/home/www/xx.com:/tmp/:/var/tmp/:/proc/ 就ok。

    评论于 2019-04-19 17:49 回复

    没那么麻烦在根目录使用cmd然后 composer install 看这样就完成了

  • 评论于 2015-03-15 12:02 举报

    请问第5步和第6步有什么差别

    1 条回复
    评论于 2015-03-16 12:45 回复

    现在好了,以前第五步是更新yii2代码的,现在都是最新的,不需要第五步了

  • 评论于 2015-03-16 13:42 举报

    感谢楼主提示,添加了环境变量安装成功了

    1 条回复
    评论于 2015-03-16 13:42 回复

    您好楼主,这个错误要怎么解决呀!谢谢

  • 评论于 2015-04-08 23:58 举报

    小马哥,我到第四步出现问题:
    D:\>cd D:\wamp\www\yii\advanced

    D:\wamp\www\yii\advanced>php -r "readfile('https://getcomposer.org/installer');"
     | php
    PHP Warning:  readfile(): Unable to find the wrapper "https" - did you forget to
     enable it when you configured PHP? in Command line code on line 1
    PHP Stack trace:
    PHP   1. {main}() Command line code:0
    PHP   2. readfile() Command line code:1
    PHP Warning:  readfile(https://getcomposer.org/installer): failed to open stream
    : Invalid argument in Command line code on line 1
    PHP Stack trace:
    PHP   1. {main}() Command line code:0
    PHP   2. readfile() Command line code:1
    
    Warning: readfile(): Unable to find the wrapper "https" - did you forget to enab
    le it when you configured PHP? in Command line code on line 1
    
    Call Stack:
        0.0020     117080   1. {main}() Command line code:0
        0.0020     117472   2. readfile() Command line code:1
    
    
    Warning: readfile(https://getcomposer.org/installer): failed to open stream: Inv
    alid argument in Command line code on line 1
    
    Call Stack:
        0.0020     117080   1. {main}() Command line code:0
        0.0020     117472   2. readfile() Command line code:1
    
    
    D:\wamp\www\yii\advanced>
    

    不知道怎么回事,求助!

    1 条回复
    评论于 2015-04-09 11:33 回复

    解决了吗 我也出现这个问题

    觉得很赞
  • 评论于 2015-04-09 22:14 举报

    第五步这里的“准备所有插件!!非常重要,少了这步一切都会失败 (!!记得配置php环境变量啊)”
    我在官网下载了composer-asset-plugin-1.0压缩包,解压到D:\phpStudy\WWW\yii2\basic目录下,然后再把php.exe的地址和composer-asset-plugin-1.0的地址放进环境变量Path中,这样对否?
    然后在cmd里面使用php composer.phar global require "fxp/composer-asset-plugin:1.0.0"命令,有错!

    求帮助

    5 条回复
    评论于 2015-04-10 13:04 回复

    解决了 不用另外下载composer-asset-plugin-1.0压缩包,只是要把命令改为“composer global require "fxp/composer-asset-plugin:1.0.0"”

    评论于 2015-04-10 13:34 回复

    还有一点,我等小白都不知道cmd输入密码是不显示的(蠢哭)

    评论于 2015-04-10 14:01 回复

    额,解决了就好

    评论于 2015-04-10 14:29 回复

    还有问题,初始化时init命令无效 怎么办?

    评论于 2015-04-16 15:39 回复

    @小马哥。我的是ubuntu安装yii2提示init丢失运行级别

  • 评论于 2015-04-15 11:37 举报

    在第6步“Installing dependencies (including require-dev)”,这里不往下走了

    5 条回复
    评论于 2015-05-24 21:33 回复

    我也是这问题,你解决了吗?我还没得解决

    评论于 2015-06-05 14:07 回复

    第六步 不往下走应该是:GitHub 的用户名和密码的原因,注册个账号,退出cmd,重新执行第6步

    评论于 2015-06-21 21:13 回复

    现在是输入token(hidden),可有解?

    评论于 2015-07-07 15:35 回复

    我也是这个问题,,现在根本不走,,求解答呀

    评论于 2015-08-05 10:32 回复

    我也遇见这个问题,输入token:

  • 评论于 2015-04-17 11:15 举报

    加油啦.......

  • 评论于 2015-04-24 10:34 举报

    访问http://127.0.0.1:8088/yii2test/frontend/web/
    提示

    Warning: require(D:\phpWeb\yii2test\frontend\web/../../vendor/autoload.php): failed to open stream: No such file or directory in D:\phpWeb\yii2test\frontend\web\index.php on line 5
    
    Fatal error: require(): Failed opening required 'D:\phpWeb\yii2test\frontend\web/../../vendor/autoload.php' (include_path='.;C:\php\pear') in D:\phpWeb\yii2test\frontend\web\index.php on line 5
    
    4 条回复
    评论于 2015-11-12 13:35 回复

    你有没有解决这个问题啊,我也遇到了

    评论于 2016-01-18 14:22 回复

    同求啊!求解决办法

    评论于 2016-11-09 09:01 回复

    我也遇到这个问题,好像是什么文件没有吧,暂时不知道怎么处理

    评论于 2017-08-25 10:30 回复

    我也遇到了这样的问题。

  • 评论于 2015-05-04 14:26 举报
    D:\yii2>php -r "readfile('https://getcomposer.org/installer');" | php
    PHP Notice:  readfile(): Unable to find the wrapper "https" - did you forget to
    enable it when you configured PHP? in Command line code on line 1
    PHP Warning:  readfile(https://getcomposer.org/installer): failed to open stream
    : Invalid argument in Command line code on line 1
    
    Warning: readfile(https://getcomposer.org/installer): failed to open stream: Inv
    alid argument in Command line code on line 1
    

    求解决!

  • 评论于 2015-05-07 12:52 举报

    你好,执行到第六步时,一直报错 could not parse version constraint ../yii2test:Invalid version string "../yii2test" ,求帮助

    1 条回复
    评论于 2015-05-11 10:54 回复

    你实在没办法了,还是下载我的安装好的源码吧

  • 评论于 2015-05-08 17:08 举报

    安装到第六步就一直不动了,请问网速慢在下载文件,还是什么情况

    觉得很赞
  • 评论于 2015-05-10 09:05 举报

    你好,进入测试页面,输入localhost/yii2/yii2test/frontend/web/index.php
    页面显示以下内容:

    Object not found!
    
    The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
    
    If you think this is a server error, please contact the webmaster.
    Error 404
    localhost
    Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15 
    
    5 条回复
    评论于 2015-05-11 10:53 回复

    你要是还解决不了的话,直接下载安装好的源码 我有的 试试
    若还是不能访问的话
    只能说明 只允许直接访问

    评论于 2015-05-11 18:34 回复

    搞定了,登录github注册进去,生成token复制粘贴进去,成功退出再进入第6步就行了

    评论于 2015-06-26 18:31 回复

    您好 token是怎么生成的哇

    评论于 2015-06-27 09:35 回复

    注册登录GitHub view profile and more -> settings -> personal access tokens

    评论于 2015-08-04 18:20 回复

    token(hidden) 这里没法输入是什么情况?你那里可以输入吗?

  • 评论于 2015-05-12 11:30 举报

    小马哥,您好,我安装YII2.0到第六步就不行了,能帮我看看吗?

    d:\WWW\yii2\advanced>php composer.phar create-project --prefer-dist --stability=
    dev yiisoft/yii2-app-advanced ../yii2test
    Installing yiisoft/yii2-app-advanced (dev-master 243a4dfe63a7b9a3f5e15531c3d1c0b
    e77b49edd)
      - Installing yiisoft/yii2-app-advanced (dev-master master)
        Loading from cache
    
    Created project in ../yii2test
    Loading composer repositories with package information
    Installing dependencies (including require-dev)
    
    Could not fetch https://api.github.com/repos/twbs/bootstrap, please create a Git
    Hub OAuth token to go over the API rate limit
    Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+
    on+Lenovo-wxh+2015-05-12+0324
    to retrieve a token. It will be stored in "C:/Users/兴宏/AppData/Roaming/Compose
    r/auth.json" for future use by Composer.
    Token (hidden):
    
    3 条回复
    评论于 2015-05-23 09:43 回复

    composer安装yii2或者laravel报错
    http://www.cnsecer.com/6994.html

    评论于 2015-10-17 17:45 回复

    我也是 要token 不知道那儿弄这个token

    评论于 2015-10-23 08:59 回复

    申请github账户个人主页setting-》-》personal access tokens 生成一个输入进去就好了,然后安装就可以继续了

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