Yii2 – 安装高级模板 advanced project template

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

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

1.安装composer

curl -sS https://getcomposer.org/installer | php  
mv composer.phar /usr/local/bin/composer 
composer self-update

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

[root@iZ942k2d5ezZ ~]# curl -sS https://getcomposer.org/installer | php 
All settings correct for using Composer
Downloading 1.0.2...

Composer successfully installed to: /root/composer.phar
Use it: php composer.phar

 

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

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

3.安装yii2

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

安装log如下:

[root@iZ942k2d5ezZ test]# composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
Running composer as root/super user is highly discouraged as packages, plugins and scripts cannot always be trusted
Installing yiisoft/yii2-app-advanced (2.0.8)
  - Installing yiisoft/yii2-app-advanced (2.0.8)
    Downloading: 100%         

Created project in yii-application
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing yiisoft/yii2-composer (2.0.4)               
    Loading from cache

  - Installing swiftmailer/swiftmailer (v5.4.1)
    Loading from cache

  - Installing bower-asset/jquery (2.2.3)
    Loading from cache

  - Installing bower-asset/yii2-pjax (v2.0.6)
    Loading from cache

  - Installing bower-asset/punycode (v1.3.2)
    Loading from cache

  - Installing bower-asset/jquery.inputmask (3.2.7)
    Loading from cache

  - Installing cebe/markdown (1.1.0)
    Loading from cache

  - Installing ezyang/htmlpurifier (v4.7.0)
    Downloading: 100%         

  - Installing yiisoft/yii2 (2.0.8)
    Downloading: 100%         

  - Installing yiisoft/yii2-swiftmailer (2.0.5)
    Loading from cache

  - Installing yiisoft/yii2-codeception (2.0.5)
    Loading from cache

  - Installing bower-asset/bootstrap (v3.3.5)
    Loading from cache

  - Installing yiisoft/yii2-bootstrap (2.0.6)
    Loading from cache

  - Installing yiisoft/yii2-debug (2.0.6)
    Loading from cache

  - Installing bower-asset/typeahead.js (v0.11.1)
    Loading from cache

  - Installing phpspec/php-diff (v1.1.0)
    Loading from cache

  - Installing yiisoft/yii2-gii (2.0.5)
    Loading from cache

  - Installing fzaninotto/faker (v1.5.0)
    Loading from cache

  - Installing yiisoft/yii2-faker (2.0.3)
    Loading from cache

fzaninotto/faker suggests installing ext-intl (*)
Writing lock file
Generating autoload files

 

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

4. yii 高级模板初始化

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

./init

执行log如下:

[root@iZ942k2d5ezZ yii-application]# ./init
Yii Application Initialization Tool v1.0

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

  [0] Development
  [1] Production

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

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

  Start initialization ...

   generate common/config/main-local.php
   generate common/config/params-local.php
   generate frontend/config/main-local.php
   generate frontend/config/params-local.php
   generate frontend/web/index.php
   generate frontend/web/index-test.php
   generate console/config/main-local.php
   generate console/config/params-local.php
   generate backend/config/main-local.php
   generate backend/config/params-local.php
   generate backend/web/index.php
   generate backend/web/index-test.php
   generate tests/codeception/config/config-local.php
   generate yii
   generate cookie validation key in backend/config/main-local.php
   generate cookie validation key in frontend/config/main-local.php
      chmod 0777 backend/runtime
      chmod 0777 backend/web/assets
      chmod 0777 frontend/runtime
      chmod 0777 frontend/web/assets
      chmod 0755 yii
      chmod 0755 tests/codeception/bin/yii

  ... initialization completed.

[root@iZ942k2d5ezZ yii-application]# 

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

前台地址:frontend/web

后台地址:backend/web

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

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

 

《Yii2 – 安装高级模板 advanced project template》有5个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注