1. 使用composer 将框架下载下来
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application(项目名称)
2.打开控制台终端,执行init
命令并选择dev
为环境。
/path/to/php-bin/php /path/to/yii-application/init
3.配置数据库信息
common/config/main-local.php
4.执行数据迁移, 如果没有写迁移文件,可以不操作这一步
/path/to/php-bin/php /path/to/yii-application/yii migrate
6.设置您的Web服务器的文档根目录
- for frontend
/path/to/yii-application/frontend/web/
and using the URLhttp://frontend.com
- for backend
/path/to/yii-application/backend/web/
and using the URLhttp://backend.com
我使用的是nginx,配置
首先在hosts中添加映射(
- Windows:
c:\Windows\System32\Drivers\etc\hosts
127.0.0.1 http://frontend.com
127.0.0.1 http://backend.com
nginx 配置
server { charset utf-8; client_max_body_size 128M; listen 9898; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name frontend.com; root "D:/cshen/yii2/frontend/web/"; index index.php; access_log D:/cshen/yii2/log/frontend-access.log; error_log D:/cshen/yii2/log/frontend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } } server { charset utf-8; client_max_body_size 128M; listen 9898; ## listen for ipv4 server_name backend.com; root "D:/cshen/yii2/backend/web/"; index index.php; access_log D:/cshen/yii2/log/backend-access.log; error_log D:/cshen/yii2/log/backend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } }
7.显示下面表示成功