Yii2 – 安装高级模板

发布时间:2018-01-13 16:48:30编辑:文明阅读(1951)

    在yii2官网,可以看到有两个版本,一个是base template,一个是advanced tempalte,高级模板更加强大一些,初始化后有一个公用的common,三个控制入口,frontend,backend,console,分别对应前台,后台,控制台,很适合线上有一定规模的网站,譬如电商网站,我们用frontend做前端显示,backend做后台,console做一些命令行的数据处理,cron定时处理脚本等,这里,我所要说的是,如何从零安装yii2的高级模板。

    composer堪称神器,类似于yum安装,自己解决包依赖,所以,安装的过程中也是用composer来安装。

    1.安装composer

    1. curl -sS https://getcomposer.org/installer | php  

    2. mv composer.phar /usr/local/bin/composer

    3. composer self-update

    第一行为下载composer,具体执行log:

    1. [root@iZ942k2d5ezZ ~]# curl -sS https://getcomposer.org/installer | php

    2. All settings correct for using Composer

    3. Downloading 1.0.2...

    4. Composer successfully installed to: /root/composer.phar

    5. Use it: php composer.phar

     

    2.初始安装:fxp/composer-asset-plugin

    1. composer global require "fxp/composer-asset-plugin:~1.1.1"

    3.安装yii2

    1. composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

    安装log如下:

    1. [root@iZ942k2d5ezZ test]# composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

    2. Running composer as root/super user is highly discouraged as packages, plugins and scripts cannot always be trusted

    3. Installing yiisoft/yii2-app-advanced (2.0.8)

    4.  - Installing yiisoft/yii2-app-advanced (2.0.8)

    5.    Downloading: 100%        

    6. Created project in yii-application

    7. Loading composer repositories with package information

    8. Updating dependencies (including require-dev)

    9.  - Installing yiisoft/yii2-composer (2.0.4)              

    10.    Loading from cache

    11.  - Installing swiftmailer/swiftmailer (v5.4.1)

    12.    Loading from cache

    13.  - Installing bower-asset/jquery (2.2.3)

    14.    Loading from cache

    15.  - Installing bower-asset/yii2-pjax (v2.0.6)

    16.    Loading from cache

    17.  - Installing bower-asset/punycode (v1.3.2)

    18.    Loading from cache

    19.  - Installing bower-asset/jquery.inputmask (3.2.7)

    20.    Loading from cache

    21.  - Installing cebe/markdown (1.1.0)

    22.    Loading from cache

    23.  - Installing ezyang/htmlpurifier (v4.7.0)

    24.    Downloading: 100%        

    25.  - Installing yiisoft/yii2 (2.0.8)

    26.    Downloading: 100%        

    27.  - Installing yiisoft/yii2-swiftmailer (2.0.5)

    28.    Loading from cache

    29.  - Installing yiisoft/yii2-codeception (2.0.5)

    30.    Loading from cache

    31.  - Installing bower-asset/bootstrap (v3.3.5)

    32.    Loading from cache

    33.  - Installing yiisoft/yii2-bootstrap (2.0.6)

    34.    Loading from cache

    35.  - Installing yiisoft/yii2-debug (2.0.6)

    36.    Loading from cache

    37.  - Installing bower-asset/typeahead.js (v0.11.1)

    38.    Loading from cache

    39.  - Installing phpspec/php-diff (v1.1.0)

    40.    Loading from cache

    41.  - Installing yiisoft/yii2-gii (2.0.5)

    42.    Loading from cache

    43.  - Installing fzaninotto/faker (v1.5.0)

    44.    Loading from cache

    45.  - Installing yiisoft/yii2-faker (2.0.3)

    46.    Loading from cache

    47. fzaninotto/faker suggests installing ext-intl (*)

    48. Writing lock file

    49. Generating autoload files

     

    执行完成上面的,yii2就下载好了,我们需要初始化

    4. yii 高级模板初始化

    进入yii-application目录(上面用composer安装的目录),执行:

    1. ./init

    执行log如下:

    1. [root@iZ942k2d5ezZ yii-application]# ./init

    2. Yii Application Initialization Tool v1.0

    3. Which environment do you want the application to be initialized in?

    4.  [0] Development

    5.  [1] Production

    6.  Your choice [0-1, or "q" to quit] 0

    7.  Initialize the application under 'Development' environment? [yes|no] yes

    8.  Start initialization ...

    9.   generate common/config/main-local.php

    10.   generate common/config/params-local.php

    11.   generate frontend/config/main-local.php

    12.   generate frontend/config/params-local.php

    13.   generate frontend/web/index.php

    14.   generate frontend/web/index-test.php

    15.   generate console/config/main-local.php

    16.   generate console/config/params-local.php

    17.   generate backend/config/main-local.php

    18.   generate backend/config/params-local.php

    19.   generate backend/web/index.php

    20.   generate backend/web/index-test.php

    21.   generate tests/codeception/config/config-local.php

    22.   generate yii

    23.   generate cookie validation key in backend/config/main-local.php

    24.   generate cookie validation key in frontend/config/main-local.php

    25.      chmod 0777 backend/runtime

    26.      chmod 0777 backend/web/assets

    27.      chmod 0777 frontend/runtime

    28.      chmod 0777 frontend/web/assets

    29.      chmod 0755 yii

    30.      chmod 0755 tests/codeception/bin/yii

    31.  ... initialization completed.

    32. [root@iZ942k2d5ezZ yii-application]#

    到这里就安装了yii2高级模板的安装,配置nginx

    前台地址:frontend/web

    后台地址:backend/web

    访问的时候,在linux下面需要将web目录下面的assets文件夹设置成可写。

    这样就完成了yii2 advanced的安装了


  • 文明
    自己顶一下1
    回复
  • 小灰宝
    请问一下博主,GII配置怎么弄??
    回复