Download and install yii2 and yii2
1. Install the yii2 advanced template directly using the archive file:
Download the archive file from yiiframework.com.
Download the compressed file of the yii2 advanced template,
Copy the yii-advanced-app-2.0.12 folder to the project's directory as follows:
View the subset directory of the yii-advanced-app-2.0.12 to find backend and frontend, backend as the background Project, frontend as the foreground project:
Configure the background project and foreground project web services as follows:
This is the nginx configuration for backend of the background Project:
Server {
Root D:/test/yii2_test/yii-advanced-app-2.0.12/advanced/backend/web /;
Index. php index.html;
Server_name dev. yii2_backend.com;
# Set $ yii_bootstrap "index.html ";
Set $ yii_bootstrap "index. php ";
Charset UTF-8;
Location /{
Index $ yii_bootstrap;
Try_files $ uri/$ yii_bootstrap? $ Args;
If (! -E $ request_filename ){
Rewrite (. *)/index. php/$1;
}
}
Location ~ ^/(Protected | framework | nbproject | themes/\ w +/views ){
Deny all;
}
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $ {
Expires 30d;
}
Location ~ . * \. (Js | css )? $ {
Expires 7d;
}
# Avoid processing of callto unexisting static files by yii
Location ~ \. (Js | css | png | jpg | gif | swf | ico | pdf | mov | fla | zip | rar) $ {
Try_files $ uri = 404;
}
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Fastcgi_split_path_info ^ (. + \. php) (. *) $;
# Let yii catch the callto unexising PHP files
Set $ fsn/$ yii_bootstrap;
If (-f $ document_root $ fastcgi_script_name ){
Set $ fsn $ fastcgi_script_name;
}
# Fastcgi_next_upstream error timeout invalid_header http_500 http_503 http_404;
# Fastcgi_pass unix:/var/run/php5-fpm.sock;
Fastcgi_pass 127.0.0.1: 9000;
Include fastcgi_params;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fsn;
# PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
Fastcgi_param PATH_INFO $ fastcgi_path_info;
Fastcgi_param PATH_TRANSLATED $ document_root $ fsn;
}
Location ~ /\. Ht {
Deny all;
}
}
This is the nginx configuration of frontend in the foreground project:
Server {
Root D:/test/yii2_test/yii-advanced-app-2.0.12/advanced/frontend/web /;
Index. php index.html;
Server_name dev. yii2_frontend.com;
# Set $ yii_bootstrap "index.html ";
Set $ yii_bootstrap "index. php ";
Charset UTF-8;
Location /{
Index $ yii_bootstrap;
Try_files $ uri/$ yii_bootstrap? $ Args;
If (! -E $ request_filename ){
Rewrite (. *)/index. php/$1;
}
}
Location ~ ^/(Protected | framework | nbproject | themes/\ w +/views ){
Deny all;
}
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $ {
Expires 30d;
}
Location ~ . * \. (Js | css )? $ {
Expires 7d;
}
# Avoid processing of callto unexisting static files by yii
Location ~ \. (Js | css | png | jpg | gif | swf | ico | pdf | mov | fla | zip | rar) $ {
Try_files $ uri = 404;
}
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Fastcgi_split_path_info ^ (. + \. php) (. *) $;
# Let yii catch the callto unexising PHP files
Set $ fsn/$ yii_bootstrap;
If (-f $ document_root $ fastcgi_script_name ){
Set $ fsn $ fastcgi_script_name;
}
# Fastcgi_next_upstream error timeout invalid_header http_500 http_503 http_404;
# Fastcgi_pass unix:/var/run/php5-fpm.sock;
Fastcgi_pass 127.0.0.1: 9000;
Include fastcgi_params;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fsn;
# PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
Fastcgi_param PATH_INFO $ fastcgi_path_info;
Fastcgi_param PATH_TRANSLATED $ document_root $ fsn;
}
Location ~ /\. Ht {
Deny all;
}
}
Configure the hosts file as follows:
127.0.0.1 dev. yii2_backend.com
127.0.0.1 dev. yii2_frontend.com
Access the background project through dev. yii2_backend.com:
Access the foreground project through dev. yii2_frontend.com as follows:
2. Use an archive file to install the common template of yii2
The general template for downloading yii2 is as follows:
Copy the normal template file to the project directory:
View the list of sub-directories of the project:
Set cookieValidationKey in the configuration file of this project:
Set cookieValidationKey to true in the config/web. php file.
Configure nginx for this project:
Server {
Root D:/test/yii2_test/yii-basic-app-2.0.11/basic/web /;
Index. php index.html;
Server_name dev. yii2_basic.com;
# Set $ yii_bootstrap "index.html ";
Set $ yii_bootstrap "index. php ";
Charset UTF-8;
Location /{
Index $ yii_bootstrap;
Try_files $ uri/$ yii_bootstrap? $ Args;
If (! -E $ request_filename ){
Rewrite (. *)/index. php/$1;
}
}
Location ~ ^/(Protected | framework | nbproject | themes/\ w +/views ){
Deny all;
}
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $ {
Expires 30d;
}
Location ~ . * \. (Js | css )? $ {
Expires 7d;
}
# Avoid processing of callto unexisting static files by yii
Location ~ \. (Js | css | png | jpg | gif | swf | ico | pdf | mov | fla | zip | rar) $ {
Try_files $ uri = 404;
}
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Fastcgi_split_path_info ^ (. + \. php) (. *) $;
# Let yii catch the callto unexising PHP files
Set $ fsn/$ yii_bootstrap;
If (-f $ document_root $ fastcgi_script_name ){
Set $ fsn $ fastcgi_script_name;
}
# Fastcgi_next_upstream error timeout invalid_header http_500 http_503 http_404;
# Fastcgi_pass unix:/var/run/php5-fpm.sock;
Fastcgi_pass 127.0.0.1: 9000;
Include fastcgi_params;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fsn;
# PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
Fastcgi_param PATH_INFO $ fastcgi_path_info;
Fastcgi_param PATH_TRANSLATED $ document_root $ fsn;
}
Location ~ /\. Ht {
Deny all;
}
}
Configure the hosts file:
127.0.0.1 dev. yii2_backend.com
127.0.0.1 dev. yii2_frontend.com
127.0.0.1 dev. yii2_basic.com
Restart nginx:
Nginx-s reload
Access the yii2 normal template project through dev. yii2_basic.com: