Composer安装Yii2高级项目模版

2018年9月3日 飞飞 阅读(2.37K)

之前写过一篇win7下安装Yii2的文章 win7系统下安装yii2步奏 ,其实在mac和liunx下安装都大同小异的,很多人会问怎么又写了一遍呢,这不因为换mac了嘛,哈哈(其实是从新整理和总结一下)。

说明

建议大家学习Yii2时用composer(若是不会的可以单独去学习), php5.4以上,低了自己升级吧

安装

1、composer安装完后执行下面语句,之后就耐心等待,会很长时间

composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

注:yii-application 是你网站的目录你可以自定义,这个目录会自动创建的。

2、打开终端执行init命令,并选择dev环境

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

3、创建一个数据库,并修改common/config/main-config.php 的 common[‘db’]配置

4、打开控制台,执行命令 /path/to/php-bin/php /path/to/yii-application/yii migrate,创建数据库。

5、配置nginx的web文件的访问路径

前台:/path/to/yii-application/frontend/web/
后台:/path/to/yii-application/backend/web/

6、nginx配置文件

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 frontend.viphper.com;
        root        /path/to/yii-application/frontend/web/;
        index       index.php;

        access_log  /path/to/yii-application/log/frontend-access.log;
        error_log   /path/to/yii-application/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 80; ## listen for ipv4
        #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
    
        server_name backend.viphper.com;
        root        /path/to/yii-application/backend/web/;
        index       index.php;
    
        access_log  /path/to/yii-application/log/backend-access.log;
        error_log   /path/to/yii-application/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、配置相应的hosts,然后浏览器直接访问 http://frontend.viphper.com,直接可以访问。

未经允许不得转载:PHP学习网 » Composer安装Yii2高级项目模版
分享到:

相关推荐

评论抢沙发

要发表评论,您必须先

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

扫码关注微信公众号

扫描关注微信公众号