有时候咱们的我的项目不可能都是同一个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
指定对应目录即可