1 安装基础环境
搭建php, nginx环境, 请参考:
http://blog.csdn.net/alex_my/article/details/53818143
首先先安装Composer
cd ~/Lib/php
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