将frontend/web/index.php复制到项目根目录,修改为:
<?php defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/common/config/bootstrap.php'); require(__DIR__ . '/frontend/config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/common/config/main-local.php'), require(__DIR__ . '/frontend/config/main.php'), require(__DIR__ . '/frontend/config/main-local.php') ); (new yii\web\Application($config))->run();
同时在frontend/config/main.php中assetManager中添加如下代码:
'assetManager' => [ 'basePath' => '@webroot/frontend/web/assets', 'baseUrl' => '@web/frontend/web/assets' ],
同样将backend/web/index.php复制到项目根目录,命名为admin.php(名称可随意,为了安全建议设置复杂点),修改为:
<?php defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/common/config/bootstrap.php'); require(__DIR__ . '/backend/config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/common/config/main-local.php'), require(__DIR__ . '/backend/config/main.php'), require(__DIR__ . '/backend/config/main-local.php') ); (new yii\web\Application($config))->run();
同时在backend/config/main.php中assetManager中添加如下代码:
'assetManager' => [ 'basePath' => '@webroot/backend/web/assets', 'baseUrl' => '@web/backend/web/assets' ],
设置之后就可以访问了,比如配置了虚拟主机yii.com,那么前台访问路径为:yii.com,后台访问路径为:yii2.com/admin.php