小马哥 2014-12-28 17:01:17 182712次浏览 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以上的!

觉得很赞
  • 评论于 2015-06-30 10:32 举报

    第五步 woaipai是嘛意思呢 公子

  • 评论于 2015-06-29 16:07 举报

    终于安装好了!!不容易啊

  • 评论于 2015-06-25 10:09 举报

    楼主没有提到第六步的时候 需要github复制链接生成token,因为要求输入token,我走了很多弯路,果断给差评!!!

    4 条回复
    评论于 2015-06-25 10:31 回复

    呵呵,以前是不需要输入token的,更新的太快,没办法 啊

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

    token怎么获取啊 求告知 !!!

    评论于 2015-06-30 16:30 回复

    登录 github

    评论于 2015-07-01 16:26 回复

    已经装好了,谢谢了!!!

  • 评论于 2015-06-21 21:31 举报

    看完这个之后最大的感触就是composer是他们谁搞出来的,这么一大堆问题。而YII2的大神也够大胆的,这么一个问题多多的玩意也要傍。真是个痛苦的世界。

  • 评论于 2015-06-19 11:01 举报

    运行第六步安装yii,输入token并保存成功后,提示

    Reading bower.json of bower-asset/jquery (2.1.0)
    

    之后一直卡着不往下走了,请问是什么情况?
    因为一直卡着不动,终止程序后,直接运行了第七歩初始化成功了,但访问测试页面时出现:

    Warning: require(D:\wampserver\wamp\www\yii2test\frontend\web/../../vendor/autoload.php): failed to open stream: No such file or directory in D:\wampserver\wamp\www\yii2test\frontend\web\index.php on line 5
    Fatal error: require(): Failed opening required 'D:\wampserver\wamp\www\yii2test\frontend\web/../../vendor/autoload.php' (include_path='.;C:\php\pear') in D:\wampserver\wamp\www\yii2test\frontend\web\index.php on line 5
    

    应该就是因为第六步没安装完成。于是重新运行了第六步创建yii2test2,但还是卡在

    Reading bower.json of bower-asset/jquery (2.1.0)
    

    处,请问有解决方案么?

    2 条回复
    评论于 2015-06-19 15:35 回复

    GitHub账号输入了,没输入的话 ,你在安装的时候 ,先登录GitHub,在安装

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

    再哪里输入账号呀?没看到提示。。。

  • 评论于 2015-06-03 17:45 举报
    denghp@denghp:~/soft/yii2-app-advanced$ composer global require "fxp/composer-asset-plugin:1.0.0"
    Changed current directory to /home/denghp/.composer
    ./composer.json has been created
    Loading composer repositories with package information
                                            
    [ErrorException]                         
    Invalid argument supplied for foreach()  
                                              
    require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [packages1] ... [packagesN]
    

    为啥直接报这个错误呢?

    1 条回复
    评论于 2015-06-04 17:52 回复

    还真不太清楚呢,按照这个教程按安装,为啥你们报的错各种各样呢

  • 评论于 2015-06-01 21:40 举报
    [Composer\Downloader\TransportException]
    The "https://packagist.org/packages.json" file could not be downloaded: SSL
    operation failed with code 1. OpenSSL Error messages:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify
    failed
    Failed to enable crypto
    failed to open stream: operation failed
    

    出现这个错误知道是什么原因吗?我openssl.dll已开启

    1 条回复
    评论于 2015-06-21 21:33 回复

    这个见某被墙的网页,说是SSL的证书过时,下载新的ssl本地判别文件

    wget http://curl.haxx.se/ca/cacert.pem
    

    并更名为ca-bundle.crt放置到默认目录

     mv cacert.pem ca-bundle.crt  | mv ca-bundle.crt /etc/pki/tls/certs/
    

    或者curl –cacert cacert.pem 方式指定调用。这是LINUX下的解决方案,我的Deepin2014.3的这样之后就好了。你可以试试下载一下这个证书,然后安装一下呢?

  • 评论于 2015-05-24 21:07 举报
    Writing lock file
    Generating autoload files
    
    D:\kadifu\advanced>composer create-project --prefer-dist --stability=dev yiisoft
    /yii2-app-advanced ../Community
    Installing yiisoft/yii2-app-advanced (dev-master b0534c270c55217d68f95723a2cb685
    5fffe4712)
    - Installing yiisoft/yii2-app-advanced (dev-master master)
      Loading from cache
    
    Created project in ../Community
    Loading composer repositories with package information
    Installing dependencies (including require-dev)
    

    第七步到这里就不动了怎么破?都等了一天了,还是这样。

    1 条回复
    评论于 2015-05-25 17:38 回复

    cmd 关掉 重新执行第7步试试

    不行的话 直接下载的yii2 安装好的源码 直接可以用:http://www.yiichina.com/tutorial/359

  • 评论于 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 生成一个输入进去就好了,然后安装就可以继续了

    觉得很赞
  • 评论于 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-08 17:08 举报

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

    觉得很赞
  • 评论于 2015-05-07 12:52 举报

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

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

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

  • 评论于 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-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-04-17 11:15 举报

    加油啦.......

  • 评论于 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-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-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-03-16 13:42 举报

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

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

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

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

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

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

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

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