1. 环境配置
1.1 yii2压缩包下载
yii2 advance版2.0.7的zip下载: https://github.com/yiisoft/yii2-app-advanced/releases
会在frontend或者backend中报错:
Warning: require(D:\Apache2.2\htdocs\yii2\basic\web/../vendor/autoload.php): failed to open stream: No such file or directory in D:\Apache2.2\htdocs\yii2\basic\web\index.php on line 7
Fatal error: require(): Failed opening required 'D:\Apache2.2\htdocs\yii2\basic\web/../vendor/autoload.php' (include_path='.;C:\php\pear') in D:\Apache2.2\htdocs\yii2\basic\web\index.php on line 7
1.1 yii2composer安装
cd到 G:\PHPProject\yii2blog
1.1.1执行安装composer
首先,下载并运行 Composer-Setup.exe
G:\PHPProject>php -r "readfile('https://getcomposer.org/installer');" | php
All settings correct for using Composer
Downloading...
Composer (version 1.6.2) successfully installed to: G:\PHPProject\yii2blog\compo
ser.phar
Use it: php composer.phar
1.1.2 安装 plugin
G:\PHPProject>php composer.phar global require "fxp/composer-asset-plugin:1.1.1"
装1.1.1的时候安装不成功,报以下错误:
Changed current directory to C:/Users/Haoran/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing fxp/composer-asset-plugin (v1.1.1): Loading from cache
Plugin installation failed, rolling back
- Removing fxp/composer-asset-plugin (v1.1.1)
[ReflectionException]
Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
[ErrorException]
Declaration of Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository
::whatProvides() should be compatible with Composer\Repository\ComposerRepo
sitory::whatProvides(Composer\DependencyResolver\Pool $pool, $name, $bypass
Filters = false)
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest]
[--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--
update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--pref
er-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authorita
tive] [--apcu-autoloader] [--] []...
后来,改成装1.1.4,成功了
G:\PHPProject>php composer.phar global require "fxp/composer-asset-plugin:1.1.4"
Changed current directory to C:/Users/Haoran/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing fxp/composer-asset-plugin (v1.1.4): Downloading (100%)
Writing lock file
Generating autoload files
1.1.3 命令行安装yii2
php composer.phar create-project --prefer-dist yiisoft/yii2-app-basic basic //在basic文件夹中安装basic版本
php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced yii2blog //在yii2blog文件夹中安装advanced版本
--stability=dev
可以不要
其中,会让去github的页面上生成一个token,直接head to就行
1.1.4 cd进yii2blog目录,init
G:\PHPProject\yii2blog>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 backend/config/main-local.php
generate backend/config/params-local.php
generate backend/config/test-local.php
generate backend/web/index-test.php
generate backend/web/index.php
generate backend/web/robots.txt
generate common/config/main-local.php
generate common/config/params-local.php
generate common/config/test-local.php
generate console/config/main-local.php
generate console/config/params-local.php
generate frontend/config/main-local.php
generate frontend/config/params-local.php
generate frontend/config/test-local.php
generate frontend/web/index-test.php
generate frontend/web/index.php
generate frontend/web/robots.txt
generate yii
generate yii_test
generate yii_test.bat
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 yii_test
... initialization completed.
G:\PHPProject\yii2blog>
1.2 本地host修改
在C:\Windows\System32\drivers\etc
中添加
127.0.0.1 frontend.yii2blog.com
127.0.0.1 backend.yii2blog.com
1.3 wamp中apache的httpd-vhost.conf增加
ServerName frontend.yii2blog.com
ServerAlias yii2blogfrontend
DocumentRoot "G:\PHPProject\yii2blog\frontend\web"
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
ServerName backend.yii2blog.com
ServerAlias yii2blogbackend
DocumentRoot "G:\PHPProject\yii2blog\backend\web"
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
1.4重启wamp服务
打开frontend.yii2blog.com和backend.yii2blog.com