频道栏目
首页 > 程序开发 > Web开发 > PHP教程 > PHP框架专栏 > Yii > 正文
Yii2创建项目
2017-01-07 09:23:00      个评论    来源:alex_my  
收藏   我要投稿

Yii2创建项目:1、安装基础环境:搭建php, nginx环境, 请参考:https://blog.csdn.net/alex_my/article/details/53818143首先先安装Composer。

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

然后切换到可以通过web访问的目录, 安装yii

cd ~/WWW/
composer global require "fxp/composer-asset-plugin:~1.1.1"

2 创建基础版

安装一个名为xyz的项目

cd ~/WWW/
composer create-project --prefer-dist yiisoft/yii2-app-basic xyz

nginx配置文件: /usr/local/etc/nginx/sites-enabled/xyz.conf

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80;
    server_name xyz.com;
    root        '/Users/alex/WWW/xyz/web/';
    index       index.php;

    # 这两个目录注意创建
    access_log  /Users/alex/WWW/xyz/runtime/logs/access.log;
    error_log   /Users/alex/WWW/xyz/runtime/logs/error.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass   127.0.0.1:9000;
        try_files $uri =404;
}

location ~ /\.(ht|svn|git) {
    deny all;
}

}

配置host: sudo vim /etc/hosts

# 添加以下代码
127.0.0.1    xyz.com

3 创建高级版

安装一个名为xyz的项目

# 先创建一个名为xyz的数据库
CREATE DATABASE IF NOT EXISTS xyz DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

cd ~/WWW/
composer create-project --prefer-dist yiisoft/yii2-app-advanced xyz
cd xyz
# 初始化项目
php init
# 进入xyz/common/config/main-local.php, 修改数据库相应的信息

前端nginx配置文件: /usr/local/etc/nginx/sites-enabled/xyz_client.conf

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80;
    server_name xyz.com;
    root        '/Users/alex/WWW/xyz/frontend/web/';
    index       index.php;

    # 这两个目录注意创建
    access_log  /Users/alex/WWW/xyz/frontend/runtime/logs/access.log;
    error_log   /Users/alex/WWW/xyz/frontend/runtime/logs/error.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass   127.0.0.1:9000;
        try_files $uri =404;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

后端nginx配置文件: /usr/local/etc/nginx/sites-enabled/xyz_server.conf

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80;
    server_name admin.xyz.com;
    root        '/Users/alex/WWW/xyz/backend/web';
    index       index.php;

    # 这两个目录注意创建
    access_log  /Users/alex/WWW/xyz/backend/runtime/logs/access.log;
    error_log   /Users/alex/WWW/xyz/backend/runtime/logs/error.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass   127.0.0.1:9000;
        try_files $uri =404;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

配置host: sudo vim /etc/hosts

# 添加以下代码
127.0.0.1    xyz.com
127.0.0.1    admin.xyz.com
点击复制链接 与好友分享!回本站首页
上一篇:配置PHPStorm IDE集成Yii框架教程
下一篇:最后一页
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训

版权所有: 红黑联盟--致力于做实用的IT技术学习网站