本篇文章给大家带来了关于php的相关知识,其中主要跟大家聊一聊怎么为Nginx和Apache配置多版本PHP,以及如何切割多个conf文件,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

有时候我们的项目不可能都是同一个 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
指定对应目录即可。
推荐学习:《PHP视频教程》
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!
redémarrage de nginx
Explication détaillée de la configuration de nginx
Explication détaillée de la configuration de nginx
Que signifie Apache ?
Comment ouvrir le fichier php
Comment supprimer les premiers éléments d'un tableau en php
Que faire si la désérialisation php échoue
Comment connecter PHP à la base de données mssql