标签:
搭建新的目录结构详细点击这里
搭建Restful API 点击这里
1.开发环境
操作系统 Windows Server 2012 R2 Datacenter
PHP架构 Apache版UPUPW PHP5.4
编程软件 Zend Studio 12.0.2
2.环境配置
解压缩UPUPW到D盘根目录,分别在UPUPW中新添加三个站点,如下
http://admin.mxq.com
http://www.mxq.com
http://api.mxq.com
网站目录都是用默认路径,然后修改D:\upupw\Apache2\conf\httpd-vhosts.conf文件,例如
将http://admin.mxq.com的DocumentRoot 修改为D:/upupw/vhosts/mxq.com/backend/web,php_admin_value open_basedir修改为D:\upupw\vhosts\mxq.com\,Directory修改为D:/upupw/vhosts/mxq.com/backend/web,其他站点也做相应修改
3.通过归档文件安装 Yii
4.添加新应用API
新部署的YII只有backend和frontend,我们手动添加api应用
5.添加数据库表前缀
打开D:\upupw\vhosts\mxq.com\common\config\main-local.php,
在db中增加子项
6.配置 Gii 为其添加允许外网访问的 IP 地址
打开D:\upupw\vhosts\mxq.com\backend\config\main-local.php,将
$config[‘modules‘][‘gii‘] = ‘yii\gii\Module‘;
一行注释掉,改为
$config[‘modules‘][‘gii‘] = [
‘class‘ => ‘yii\gii\Module‘,
‘allowedIPs‘ => [‘127.0.0.1‘, ‘192.168.0.*‘]
];
192.168.0.*为您的IP地址
开发阶段进行init初始化操作会将其覆盖掉,所以我们直接修改D:\upupw\vhosts\mxq.com\environments\dev\backend\config\main-local.php,其他的应用也这样修改
7.开启国际化支持,源代码中文和设置时区、字符集默认UTF-8
因为所有应用都用中文,所以我们将开启设置在common中。
打开D:\upupw\vhosts\mxq.com\common\config\main.php,
在components一行上加入
‘language‘ => ‘zh-CN‘, // 启用国际化支持
‘sourceLanguage‘ => ‘zh-CN‘, // 源代码采用中文
‘timeZone‘ => ‘Asia/Shanghai‘, // 设置时区
8.禁用api应用的默认布局
打开D:\upupw\vhosts\mxq.com\api\config\main.php,
在components一行上加入
‘layout‘ => false,
9.去掉地址栏URL编码
http://yii2/index.php?r=site%2Flogin
http://yii2/index.php?r=site/login
以上两个网址,那个看起来更清晰明了呢?显而易见是第二个,为了达到这个效果,可以进行如下修改
打开D:\upupw\vhosts\mxq.com\vendor\yiisoft\yii2\web\UrlManager.php将
$url = "$baseUrl?{$this->routeParam}=" . urlencode($route);
改为
$url = "$baseUrl?{$this->routeParam}=" . $route;
10.为Controller制定布局模版
在init方法中写入
$this->layout = ‘‘;
引号之间填入您的布局文件名
11.Apache下三个应用公用一个高级模版配置
<VirtualHost *:80> DocumentRoot "D:/upupw/vhosts/mxq.com/backend/web" ServerName admin.mxq.com:80 ServerAlias admin ServerAdmin webmaster@admin.mxq.com DirectoryIndex index.html index.htm index.php default.php app.php u.php ErrorLog logs/admin.mxq.com-error.log CustomLog logs/admin.mxq.com-access_%Y%m%d.log comonvhost php_admin_value open_basedir "D:\upupw\vhosts\mxq.com\;D:\upupw\memcached\;D:\upupw\phpmyadmin\;D:\upupw\temp\;C:\Windows\Temp\" <Directory "D:/upupw/vhosts/mxq.com/backend/web"> Options FollowSymLinks AllowOverride All Require all granted </Directory> <LocationMatch "/(inc)/(.*)$"> AllowOverride none Require all denied </LocationMatch> <LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$"> AllowOverride none Require all denied </LocationMatch> </VirtualHost> <VirtualHost *:80> DocumentRoot "D:/upupw/vhosts/mxq.com/frontend/web" ServerName www.mxq.com:80 ServerAlias www ServerAdmin webmaster@www.mxq.com DirectoryIndex index.html index.htm index.php default.php app.php u.php ErrorLog logs/www.mxq.com-error.log CustomLog logs/www.mxq.com-access_%Y%m%d.log comonvhost php_admin_value open_basedir "D:\upupw\vhosts\mxq.com\;D:\upupw\memcached\;D:\upupw\phpmyadmin\;D:\upupw\temp\;C:\Windows\Temp\" <Directory "D:/upupw/vhosts/mxq.com/frontend/web"> Options FollowSymLinks AllowOverride All Require all granted </Directory> <LocationMatch "/(inc)/(.*)$"> AllowOverride none Require all denied </LocationMatch> <LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$"> AllowOverride none Require all denied </LocationMatch> </VirtualHost> <VirtualHost *:80> DocumentRoot "D:/upupw/vhosts/mxq.com/api/web" ServerName api.mxq.com:80 ServerAlias api ServerAdmin webmaster@api.mxq.com DirectoryIndex index.html index.htm index.php default.php app.php u.php ErrorLog logs/api.mxq.com-error.log CustomLog logs/api.mxq.com-access_%Y%m%d.log comonvhost php_admin_value open_basedir "D:\upupw\vhosts\mxq.com\;D:\upupw\memcached\;D:\upupw\phpmyadmin\;D:\upupw\temp\;C:\Windows\Temp\" <Directory "D:/upupw/vhosts/mxq.com/api/web"> Options FollowSymLinks AllowOverride All Require all granted </Directory> <LocationMatch "/(inc)/(.*)$"> AllowOverride none Require all denied </LocationMatch> <LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$"> AllowOverride none Require all denied </LocationMatch> </VirtualHost>
标签:
原文地址:http://www.cnblogs.com/derrck/p/5210573.html