关于nginx:为Nginx和Apache配置多版本PHP切割多个conf文件

3次阅读

共计 1124 个字符,预计需要花费 3 分钟才能阅读完成。

有时候咱们的我的项目不可能都是同一个 PHP 版本,须要每个我的项目都配置不同版本的 PHP,宝塔和 PHPStudy 就是通过以下配置实现的:

Nginx

切割 conf(非选)

nginx.conf 增加

include vhosts/*.conf;

这样 Nginx 会主动引入 当前目录 ->vhosts目录下的所有 *.conf 文件,不便每个我的项目独自治理 Nginx 配置文件

配置多版本 PHP

conf 文件中减少

server {
        listen        80;
        server_name  localhost;
        root   "D:/WWW";
        location / {
            index index.php index.html;
            include D:/WWW/nginx.htaccess;
            autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9010;
            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  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

fastcgi_pass 是 PHP 执行 IP+ 端口
fastcgi_index 默认 PHP 文件
fastcgi_split_path_info 是正则
fastcgi_param 是 PHP 所在目录(Nginx 会主动获取赋值给 $fastcgi_script_name)

假如咱们有两个 PHP 版本,一个 PHP5,一个 PHP7,那么能够将他们别离运行在不同的端口上,而后通过设置 fastcgi_pass 参数来实现每个我的项目不同 PHP 版本

Apache

切割 conf(非选)

httpd.conf 增加

Include conf/vhosts/*.conf

这样 Apache 会主动引入 Apache 装置目录 ->conf->vhosts 目录下的所有 *.conf 文件,不便每个我的项目独自治理 Apache 配置文件

配置多版本 PHP

conf 文件里增加

FcgidInitialEnv PHPRC "D:/Extensions/php/php8.2.2-nts"
    AddHandler fcgid-script .php
    FcgidWrapper "D:/Extensions/php/php8.2.2-nts/php-cgi.exe" .php

指定对应目录即可

正文完
 0