本篇文章給大家?guī)?lái)了關(guān)于php的相關(guān)知識(shí),其中主要跟大家聊一聊怎么為Nginx和Apache配置多版本PHP,以及如何切割多個(gè)conf文件,感興趣的朋友下面一起來(lái)看一下吧,希望對(duì)大家有幫助。
有時(shí)候我們的項(xiàng)目不可能都是同一個(gè) PHP 版本,需要每個(gè)項(xiàng)目都配置不同版本的 PHP,寶塔和 PHPStudy 就是通過(guò)以下配置實(shí)現(xiàn)的:
Nginx
切割 conf(非選)
在 nginx.conf 添加
include vhosts/*.conf;
這樣 Nginx 會(huì)自動(dòng)引入當(dāng)前目錄->vhosts 目錄下的所有 *.conf 文件,方便每個(gè)項(xiàng)目單獨(dú)管理 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 執(zhí)行 IP + 端口
fastcgi_index 默認(rèn) PHP 文件
fastcgi_split_path_info 是正則
fastcgi_param 是 PHP 所在目錄(Nginx 會(huì)自動(dòng)獲取賦值給 $fastcgi_script_name)
假設(shè)我們有兩個(gè) PHP 版本,一個(gè) PHP5,一個(gè) PHP7,那么可以將他們分別運(yùn)行在不同的端口上,然后通過(guò)設(shè)置 fastcgi_pass 參數(shù)來(lái)實(shí)現(xiàn)每個(gè)項(xiàng)目不同 PHP 版本
Apache
切割 conf(非選)
在 httpd.conf 添加
Include conf/vhosts/*.conf
這樣 Apache 會(huì)自動(dòng)引入 Apache安裝目錄->conf->vhosts 目錄下的所有 *.conf 文件,方便每個(gè)項(xiàng)目單獨(dú)管理 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
指定對(duì)應(yīng)目錄即可。