当前位置:Gxlcms > PHP教程 > yii2框架的下载安装图文教程

yii2框架的下载安装图文教程

时间:2021-07-01 10:21:17 帮助过:22人阅读

1.直接使用归档文件安装yii2的高级模板:

从 yiiframework.com 下载归档文件。

下载yii2的高级模板的压缩文件,

将yii-advanced-app-2.0.12文件夹复制到项目的目录中如下:

查看yii-advanced-app-2.0.12的子集目录发现有backend和frontend,backend为后台项目, frontend为 前台项目:

配置后台项目和前台的项目web服务如下:

这是后台项目backend的nginx配置:

  1. server {
  2. root D:/test/yii2_test/yii-advanced-app-2.0.12/advanced/backend/web/;
  3. index index.php index.html;
  4. server_name dev.yii2_backend.com;
  5. # set $yii_bootstrap "index.html";
  6. set $yii_bootstrap "index.php";
  7. charset utf-8;
  8. location / {
  9. index $yii_bootstrap;
  10. try_files $uri $uri/ $yii_bootstrap?$args;
  11. if (!-e $request_filename) {
  12. rewrite (.*) /index.php/$1;
  13. }
  14. }
  15. location ~ ^/(protected|framework|nbproject|themes/\w+/views) {
  16. deny all;
  17. }
  18. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
  19. expires 30d;
  20. }
  21. location ~ .*\.(js|css)?$ {
  22. expires 7d;
  23. }
  24. #avoid processing of calls to unexisting static files by yii
  25. location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
  26. try_files $uri =404;
  27. }
  28. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  29. #
  30. location ~ \.php$ {
  31. fastcgi_split_path_info ^(.+\.php)(.*)$;
  32. #let yii catch the calls to unexising PHP files
  33. set $fsn /$yii_bootstrap;
  34. if (-f $document_root$fastcgi_script_name){
  35. set $fsn $fastcgi_script_name;
  36. }
  37. #fastcgi_next_upstream error timeout invalid_header http_500 http_503 http_404;
  38. #fastcgi_pass unix:/var/run/php5-fpm.sock;
  39. fastcgi_pass 127.0.0.1:9000;
  40. include fastcgi_params;
  41. fastcgi_param SCRIPT_FILENAME $document_root$fsn;
  42. #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
  43. fastcgi_param PATH_INFO $fastcgi_path_info;
  44. fastcgi_param PATH_TRANSLATED $document_root$fsn;
  45. }
  46. location ~ /\.ht {
  47. deny all;
  48. }
  49. }

这是前台项目frontend的nginx配置:

  1. server {
  2. root D:/test/yii2_test/yii-advanced-app-2.0.12/advanced/frontend/web/;
  3. index index.php index.html;
  4. server_name dev.yii2_frontend.com;
  5. # set $yii_bootstrap "index.html";
  6. set $yii_bootstrap "index.php";
  7. charset utf-8;
  8. location / {
  9. index $yii_bootstrap;
  10. try_files $uri $uri/ $yii_bootstrap?$args;
  11. if (!-e $request_filename) {
  12. rewrite (.*) /index.php/$1;
  13. }
  14. }
  15. location ~ ^/(protected|framework|nbproject|themes/\w+/views) {
  16. deny all;
  17. }
  18. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
  19. expires 30d;
  20. }
  21. location ~ .*\.(js|css)?$ {
  22. expires 7d;
  23. }
  24. #avoid processing of calls to unexisting static files by yii
  25. location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
  26. try_files $uri =404;
  27. }
  28. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  29. #
  30. location ~ \.php$ {
  31. fastcgi_split_path_info ^(.+\.php)(.*)$;
  32. #let yii catch the calls to unexising PHP files
  33. set $fsn /$yii_bootstrap;
  34. if (-f $document_root$fastcgi_script_name){
  35. set $fsn $fastcgi_script_name;
  36. }
  37. #fastcgi_next_upstream error timeout invalid_header http_500 http_503 http_404;
  38. #fastcgi_pass unix:/var/run/php5-fpm.sock;
  39. fastcgi_pass 127.0.0.1:9000;
  40. include fastcgi_params;
  41. fastcgi_param SCRIPT_FILENAME $document_root$fsn;
  42. #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
  43. fastcgi_param PATH_INFO $fastcgi_path_info;
  44. fastcgi_param PATH_TRANSLATED $document_root$fsn;
  45. }
  46. location ~ /\.ht {
  47. deny all;
  48. }
  49. }

配置hosts文件如下:

127.0.0.1 dev.yii2_backend.com
127.0.0.1 dev.yii2_frontend.com

通过dev.yii2_backend.com访问后台项目:

通过dev.yii2_frontend.com访问前台项目如下:

2. 使用归档文件安装yii2的普通模板

下载yii2的普通模板如下:

复制普通模板文件到项目目录:

查看该项目子集目录列表:

在该项目的配置文件中设置cookieValidationKey:

在config/web.php文件中设置cookieValidationKey为true

为该项目配置nginx:

  1. server {
  2. root D:/test/yii2_test/yii-basic-app-2.0.11/basic/web/;
  3. index index.php index.html;
  4. server_name dev.yii2_basic.com;
  5. # set $yii_bootstrap "index.html";
  6. set $yii_bootstrap "index.php";
  7. charset utf-8;
  8. location / {
  9. index $yii_bootstrap;
  10. try_files $uri $uri/ $yii_bootstrap?$args;
  11. if (!-e $request_filename) {
  12. rewrite (.*) /index.php/$1;
  13. }
  14. }
  15. location ~ ^/(protected|framework|nbproject|themes/\w+/views) {
  16. deny all;
  17. }
  18. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
  19. expires 30d;
  20. }
  21. location ~ .*\.(js|css)?$ {
  22. expires 7d;
  23. }
  24. #avoid processing of calls to unexisting static files by yii
  25. location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
  26. try_files $uri =404;
  27. }
  28. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  29. #
  30. location ~ \.php$ {
  31. fastcgi_split_path_info ^(.+\.php)(.*)$;
  32. #let yii catch the calls to unexising PHP files
  33. set $fsn /$yii_bootstrap;
  34. if (-f $document_root$fastcgi_script_name){
  35. set $fsn $fastcgi_script_name;
  36. }
  37. #fastcgi_next_upstream error timeout invalid_header http_500 http_503 http_404;
  38. #fastcgi_pass unix:/var/run/php5-fpm.sock;
  39. fastcgi_pass 127.0.0.1:9000;
  40. include fastcgi_params;
  41. fastcgi_param SCRIPT_FILENAME $document_root$fsn;
  42. #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
  43. fastcgi_param PATH_INFO $fastcgi_path_info;
  44. fastcgi_param PATH_TRANSLATED $document_root$fsn;
  45. }
  46. location ~ /\.ht {
  47. deny all;
  48. }
  49. }

配置hosts文件:

127.0.0.1 dev.yii2_backend.com
127.0.0.1 dev.yii2_frontend.com
127.0.0.1 dev.yii2_basic.com

重启nginx:

nginx -s reload

通过dev.yii2_basic.com访问yii2普通模板项目:

以上就是yii2框架的下载安装图文教程的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行