Composer安装Yii2高级项目模版

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

说明

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

安装

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

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

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

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

  1. /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配置文件

  1. server {
  2. charset utf-8;
  3. client_max_body_size 128M;
  4.  
  5. listen 80; ## listen for ipv4
  6. #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
  7.  
  8. server_name frontend.viphper.com;
  9. root /path/to/yii-application/frontend/web/;
  10. index index.php;
  11.  
  12. access_log /path/to/yii-application/log/frontend-access.log;
  13. error_log /path/to/yii-application/log/frontend-error.log;
  14.  
  15. location / {
  16. # Redirect everything that isn't a real file to index.php
  17. try_files $uri $uri/ /index.php$is_args$args;
  18. }
  19.  
  20. # uncomment to avoid processing of calls to non-existing static files by Yii
  21. #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
  22. # try_files $uri =404;
  23. #}
  24. #error_page 404 /404.html;
  25.  
  26. # deny accessing php files for the /assets directory
  27. location ~ ^/assets/.*\.php$ {
  28. deny all;
  29. }
  30.  
  31. location ~ \.php$ {
  32. include fastcgi_params;
  33. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  34. fastcgi_pass 127.0.0.1:9000;
  35. #fastcgi_pass unix:/var/run/php5-fpm.sock;
  36. try_files $uri =404;
  37. }
  38. location ~* /\. {
  39. deny all;
  40. }
  41. }
  42. server {
  43. charset utf-8;
  44. client_max_body_size 128M;
  45. listen 80; ## listen for ipv4
  46. #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
  47. server_name backend.viphper.com;
  48. root /path/to/yii-application/backend/web/;
  49. index index.php;
  50. access_log /path/to/yii-application/log/backend-access.log;
  51. error_log /path/to/yii-application/log/backend-error.log;
  52. location / {
  53. # Redirect everything that isn't a real file to index.php
  54. try_files $uri $uri/ /index.php$is_args$args;
  55. }
  56. # uncomment to avoid processing of calls to non-existing static files by Yii
  57. #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
  58. # try_files $uri =404;
  59. #}
  60. #error_page 404 /404.html;
  61.  
  62. # deny accessing php files for the /assets directory
  63. location ~ ^/assets/.*\.php$ {
  64. deny all;
  65. }
  66.  
  67. location ~ \.php$ {
  68. include fastcgi_params;
  69. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  70. fastcgi_pass 127.0.0.1:9000;
  71. #fastcgi_pass unix:/var/run/php5-fpm.sock;
  72. try_files $uri =404;
  73. }
  74. location ~* /\. {
  75. deny all;
  76. }
  77. }

7、配置相应的hosts,然后浏览器直接访问 http://frontend.viphper.com,直接可以访问。

posted @ 2020-03-22 18:54  沙黾农  阅读(291)  评论(0)    收藏  举报
股票配资排名 股票配资 刷Q币 棋牌游戏赚钱技巧