简介
现在几乎所有的PHP框架都需要使用pathinfo来读取url信息。
安装宝塔面板
略
通过宝塔安装PHP7.4
略
PHP开启pathinfo
也可直接在面板中开启:
配置nginx
打开D:\BtSoft\nginx\conf\php\74.conf
,在try_files $uri =404;
前添加#
注释掉,否则访问时会出现404
修改后的74.conf
文件内容如下:
location ~ \.php(.*)$ {
#try_files $uri =404;
fastcgi_pass 127.0.0.1:20074;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
配置后已支持使用/index.php/foo/bar
来访问了。
省略index.php
为了让URL更好看,可以省略URL路径中的index.php
添加伪静态规则:
配置后已支持使用/foo/bar
访问。
指定目录使用php5版本
有些时候我们希望在指定的目录中使用PHP5的版本来访问。先通过宝塔安装PHP5.6版本。打开D:\BtSoft\nginx\conf\php\74.conf
,在文件顶部加入:
location ~ /hello(.*)$ {
fastcgi_pass 127.0.0.1:20056;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
这样访问/hello/目录下的文件将使用php5.6版本
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://sg.hqyman.cn/post/9585.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~