The ultimate solution for thinkphp3.2.x PathInfo under LNMP

Source: Internet
Author: User
Tags rtrim
Recently used the LNMP one-click Install package 1.2 version, and then build the thinkphp program can not use PathInfo mode anyway. Find a lot of solutions online, and finally found the problem.
1, LNMP a key installation package php.ini inside cgi.fix_pathinfo=0. This value is 1 by default when PHP is installed properly. If you use LNMP one-click installation package must be modified to 1, of course, you can also modify the thinkphp source code.
2, modify your configuration file, comment out try_files $uri = 404; open include pathinfo.conf; then url_model=1 can support PathInfo.

Location ~ [^/]\.php (/|$)        {            # comment Try_files $uri =404, to enable PathInfo            #try_files $uri =404;            Fastcgi_pass  Unix:/tmp/php-cgi.sock;            Fastcgi_index index.php;            Include fastcgi.conf;            Include pathinfo.conf;        }

3. If you think cgi.fix_pathinfo=1 is unsafe, you can use rewrite mode.
Under the virtual host root line, add the following

if (!-e $request _filename) {   rewrite  ^ (. *) $  /index.php?s=$1 last  ;   break;    }

4. The reason why PathInfo is not available is that cgi.fix_pathinfo=0 $_server[' php_self ' is not getting index.php.
And the source of thinkphp

if (is_cgi) {            //cgi/fastcgi mode            $_temp  = explode ('. php ', $_server[' php_self ']);            Define (' _php_file_ ',    RTrim (str_replace ($_server[' http_host '), ' ', $_temp[0]. php '), '/');        } else {            define (' _php_file_ ',    rtrim ($_server[' script_name '], '/'));        }

Because $_server[' php_self ' gets less than index.php, $_temp is empty, resulting in _php_file_ for the. Php,u function The address that is generated is also. PHP is not accessible. If you do not want to modify the configuration of PHP can only modify the source code here. Change the If inside to be the same as the other one.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.