LNMP1.3 install Linux environment with one click, configure Nginx Run ThinkPHP3.2
Have you ever met: After installing LNMP1.3 environment, run thinkphp 3.2, can only open home page, cannot access controller, reported 404 error.
Follow these 3-step settings to resolve.
Thinkphp supports four types of URL patterns: Normal mode, PATHINFO, rewrite, and compatibility mode, system default PATHINFO mode.
LNMP1.3 Once the installation is complete, the default support rewrite, need to manually open PATHINFO.
1th Step Modification: php.ini file
Location:/usr/local/php/etc/php.ini
Search Find: Cgi.fix_pathinfo configuration item, default is 0, modify to 1, turn on pathinfo option.
1:
2nd Step Modification: Nginx configuration file (the author uses the virtual domain name profile:/usr/local/nginx/conf/vhost/*.conf)
Locate the configuration options for the server:
The default is only include enable-php.conf, please comment out;
Then add a line: include enable-php-pathinfo.conf
Such as:
123 |
#error_page 404 /404.html; #include enable-php.conf; # Register this line include enable-php-pathinfo.conf; # Join this line |
2:
To continue with the modification, add the following configuration information:
1234567891011121314151617 |
Location ~. php{ Set $path _info ""; Set $real _script_name $fastcgi _script_name; #如果地址与引号内的正则表达式匹配 if ($fastcgi _script_name ~ "^ (. +?\.php) (/.+) $") { #将文件地址赋值给变量 $real _script_name Set $real _script_name $; #将文件地址后的参数赋值给变量 $path _info set $path _info; } #配置fastcgi的一些参数 fastcgi_param script_filename $document _root$real_script_name; Fastcgi_param script_name $real _script_name; Fastcgi_param path_info $path _info;} |
In Nginx, you can resolve other Web server environments that do not support pathinfo by configuring a forwarding rule implementation in nginx.conf.
#如果请求既不是一个文件, not a directory, execute the rewrite rule
1234567 |
if (!-e $request _filename) {#地址作为将参数rewrite到index. php. Rewrite ^/(. *) $/index.php/$1; #若是子目录则使用下面这句, change the subdir to a directory name. #rewrite ^/subdir/(. *) $/subdir/index.php/$1;} |
Official Source: Http://document.thinkphp.cn/manual_3_2.html#url_rewrite
3rd Step: Restart the LNMP environment, the configuration takes effect.
Final effect test:
1. Removed the index.php
2. You can access the methods under the controller.
3. The U method is correct.
3:
Reference: Author configuration file Example:
12345678910111213141516171819202122232425262728293031323334353637383940414243 |
server {Listen 80; #listen [::]:80; server_name tp32.com; Index index.html index.htm index.php default.html default.htm default.php; root/home/wwwroot/tp32.com; Include other.conf; #error_page 404/404.html; #include enable-php.conf; Include enable-php-pathinfo.conf; #加入这行 location ~. php {Set $path _info ""; Set $real _script_name $fastcgi _script_name; #如果地址与引号内的正则表达式匹配 if ($fastcgi _script_name ~ "^ (. +?\.php) (/.+) $") {#将文件地址赋值给变量 $real _script_name Set $real _script_name $; #将文件地址后的参数赋值给变量 $path _info set $path _info; } #配置fastcgi的一些参数 fastcgi_param script_filename $document _root$real_script_name; Fastcgi_param script_name $real _script_name; Fastcgi_param path_info $path _info; } #如果请求既不是一个文件, not a directory, then execute the rewrite rule if (!-e $request _FileName) {#地址作为将参数rewrite到index. php. Rewrite ^/(. *) $/index.php/$1; #若是子目录则使用下面这句, change the subdir to a directory name. #rewrite ^/subdir/(. *) $/subdir/index.php/$1; } Access_log/home/wwwlogs/tp32.com.log; } |
Entry file index.php
12 |
The NGINX environment prevents U-Method output error define (' __app__ ', '); |
Reference:
Http://www.thinkphp.cn/topic/3138.html
LNMP1.3 install Linux environment with one click, configure Nginx Run ThinkPHP3.2