微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Composer安装Yii2高级项目模版

之前写过一篇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,直接可以访问。

原文地址:https://www.toutiao.com/article/7109745519475409448/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐