下载github上的完事安装包(本机环境使用Composer安装非常慢) https://github.com/yiisoft/yii2-app-advanced
解压到文件目录 wwwroot/sh,控制台进入此目录,使用init命令初始化;
创建数据库,并配置配置文件 common/config/main-local.php 设置数据库连接
执行数据库迁移命令:
yii migrate
配置服务器文档的根目录,我这里使用一个后台和一个API
back.domain.com
api.domain.com
复制一个backend文件,并重命名为api
配置nginx文件:配置代码
重启nginx服务器
#START-SITE
server {
charset utf-8;
client_max_body_size 128M; listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name api.domain.com; ##API域名
root D:/wwwroot/shanghai/api/web; ##API iindex地址
index index.php; #access_log D:/wwwroot/shanghai/access.api.log main;
#error_log D:/wwwroot/shanghai//error.api.log; location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php?$args;
} # location ~ \.php$ {
# include fastcgi.conf;
# fastcgi_pass 127.0.0.1:9000;
# #fastcgi_pass unix:/var/run/php5-fpm.sock;
# try_files $uri =404;
# }
location ~ \.php$ {
root D:/wwwroot/shanghai/api/web;
fastcgi_pass 127.0.0.1:4570;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#error_page 404 /404.html; location ~ /\.(ht|svn|git) {
deny all;
}
}
#END-SITE
#START-SITE
server {
charset utf-8;
client_max_body_size 128M; listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name back.domain.com; ##前台域名
root D:/wwwroot/shanghai/backend/web; ##这是前台index地址
index index.php; #access_log D:/wwwroot/shanghai/access.backend.log main;
#error_log D:/wwwroot/shanghai//error.backend.log; location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php?$args;
} # location ~ \.php$ {
# include fastcgi.conf;
# fastcgi_pass 127.0.0.1:9000;
# #fastcgi_pass unix:/var/run/php5-fpm.sock;
# try_files $uri =404;
# }
location ~ \.php$ {
root D:/wwwroot/shanghai/backend/web;
fastcgi_pass 127.0.0.1:4570;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#error_page 404 /404.html; location ~ /\.(ht|svn|git) {
deny all;
}
}
#END-SITE