yii2.0高级版本框架搭建

时间:2021-12-07 07:49:00

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

yii2.0高级版本框架搭建

3.配置数据库信息

common/config/main-local.php

yii2.0高级版本框架搭建

4.执行数据迁移, 如果没有写迁移文件,可以不操作这一步

/path/to/php-bin/php /path/to/yii-application/yii migrate

yii2.0高级版本框架搭建

6.设置您的Web服务器的文档根目录

  • for frontend /path/to/yii-application/frontend/web/ and using the URL http://frontend.com
  • for backend /path/to/yii-application/backend/web/ and using the URL http://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.显示下面表示成功

yii2.0高级版本框架搭建

yii2.0高级版本框架搭建