LAMP之路

不积跬步,无以至千里!

LNMP部署ThinkPHP程序

2013-11-21 一抹阳光 环境架设

写在前面的话:

ThinkPHP的四种URL模式:0(普通模式);1(PATHINFO模式);2(REWRITE模式);3(兼容模式)

nginx需要PATHINFO模式,但需要更改nginx配置文件让其支持PATHINFO模式。

 

系统环境:

系统:CentOS-6.4-x86_64

web服务器:nginx1.2.7

PHP版本:PHP5.3.17

数据库版本:MySQL5.5.28

 

一、安装LNMP1.0一键安装包:

http://lnmp.org/install.html

按照以上版本安装环境

 

二、修改配置文件

1.修改php配置文件php.ini,将其中cgi.fix_pathinfo = 0,值改为1

重启php-fpm

2.ssh里执行:

cat > /usr/local/nginx/conf/pathinfo.conf << 'EOF'
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "(.+?\.php)(/.*)") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;

EOF


再将虚拟主机配置文件里的location ~ .*\.(php|php5)?$ 替换为:location ~ .*\.php
再在include fcgi.conf; 下面添加一行include pathinfo.conf;
重启nginx

完整的虚拟主机配置文件如下:

server
        {
                listen       80;
                server_name www.lnmp.org;
                index index.html index.htm index.php;
                root  /home/wwwroot/lnmp;

                location ~ .*\.php
                        {
                                try_files $uri =404;
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fcgi.conf;
                                include pathinfo.conf;
                        }

                location /status {
                        stub_status on;
                        access_log   off;
                }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                access_log  /home/wwwlogs/lnmp.log  lnmp;

        }


将ThinkPHP的URL模式设置成PATHINFO。

ThinkPHP就可以在nginx中运行了。

评论:

你好
2017-12-08 14:37
还是一头雾水
glenn
2017-02-28 14:08
不错,谢谢分享