我们使用PHP 7.0运行XAMPP,因为我们的新产品需要PHP 7。
但也有一些旧的项目使用mysql_connect等函数。这些在PHP 7.0中被删除。
那么,是否有一种方法可以轻松地在XAMPP中更改PHP版本?
注意:请不要建议将旧项目升级到与新版本兼容,因为我无法做到这一点 这些决定是我作为开发人员(只是一名员工)无法得到的。
我们使用PHP 7.0运行XAMPP,因为我们的新产品需要PHP 7。
但也有一些旧的项目使用mysql_connect等函数。这些在PHP 7.0中被删除。
那么,是否有一种方法可以轻松地在XAMPP中更改PHP版本?
注意:请不要建议将旧项目升级到与新版本兼容,因为我无法做到这一点 这些决定是我作为开发人员(只是一名员工)无法得到的。
当前回答
在命令提示符窗口(cmd.exe)中运行此命令。
set PATH=C:\xampp\php;%PATH%
根据安装PHP 7的位置进行更改。
其他回答
我只是想分享我的新发现:https://laragon.org/docs/index.html
我刚用了一个小时,看起来很不错。
你可以添加和切换PHP版本, 它有一键安装Wordpress, laravel等 它自动创建vhosts与每个应用程序的名称(例如。appname.test) 你可以选择你当前的htdocs文件夹作为WWW根文件夹 您只需添加其他PHP版本,将它们提取到文件夹中,并从列表中选择它们 它会在每次更改后自动重载apache 添加phpMyAdmin就像下载它一样简单,并把它放在{LARAGON_DIR}\etc\apps\phpMyAdmin等…
拉拉贡文档
如何添加另一个PHP版本的Laragon
如何添加phpMyAdmin到Laragon
我和拉拉贡没有任何关系。刚刚在谷歌上找到它,寻找“XAMPP Windows替代品”
安装一个XAMPP就可以安装多个版本的PHP。下面的说明适用于Windows。
为Windows安装最新的XAMPP版本(在我的例子中是PHP 7.1) 确保Apache没有从XAMPP控制面板运行 将XAMPP安装目录下的php目录重命名,如C:\ XAMPP \php改为C:\ XAMPP \php-7.1.11。 下载你想要运行的PHP版本(例如:PHP 5.4.45) 将php目录从您下载的版本移动到XAMPP安装目录。重命名它,使其包含PHP版本。例如C:\xampp\php-5.4.45。
现在你需要编辑XAMPP和Apache配置:
在C:\xampp\apache\conf\httpd.conf中,找到PHP的xampp设置,您应该将其更改为如下内容:
你必须注释(用#)其他的PHP版本,所以只有一个包含将被解释在同一时间。
#XAMPP settings PHP 7
Include "conf/extra/httpd-xampp.conf.7.1"
#XAMPP settings PHP 5.4.45
#Include "conf/extra/httpd-xampp.conf.5.4.45"
Now in C:\xampp\apache\conf\extra directory rename httpd-xampp.conf to httpd-xampp.conf.7.1 and add a new configuration file for httpd-xampp.conf.5.4.45. In my case, I copied the conf file of another installation of XAMPP for php 5.5 as the syntax may be slightly different for each version. Edit httpd-xampp.conf.5.4.45 and httpd-xampp.conf.7.1 and replace there all the reference to the php directory with the new php-X.X version. There are at least 10 changes to be made here for each file. You now need to edit php.ini for the two versions. For example for php 7.1, edit C:\xampp\php-7.1.11\php.ini where you will replace the path of the php directory for include_path, browscap, error_log, extension_dir..
就是这样。您现在可以从XAMPP控制面板启动Apache。要从一个版本切换到另一个版本,你只需要在重新启动apache之前编辑C:\xampp\apache\conf\httpd.conf并更改包含的PHP版本。
简单和最容易的步骤
Install xampps whatever php version you want. Rename xampp folder in C:\xampp to C:\xampp74 Download and install another xampps like I do: (first is php7 second is php8) Now you have two different xampp with different php version Now whenever you want to change you just nned to follow stop Apache and mysql and Quit xampp Rename folder to xampp an change other xampp folder with it's version name to remember Again Start the Apache and mysql (some time it can't rename then restart and try)
我需要做同样的事情,所以我谷歌了一下,结果发现堆栈溢出,而OP也有同样的问题……所以我的发现…我尝试从不同的方向重命名文件,我的结论基本上是它花了我太长时间。所以我最终只是从这里安装了第7版:
https://www.apachefriends.org/index.html (在尝试xampp之前杀死服务并退出)
当被问到在哪里放置目录名称时,就像这样(给它一个不同的名字):
and
DONEZO !现在只要确保在来回交换之前杀死服务并退出,你就有2个无菌的XAMPP环境可以玩。
万岁!现在我真的可以去工作了!
我正在做一个10年前的项目。5.6是我的默认值。还有一些老的小项目只能使用5.2,我还想为我的个人项目开发7.3.8的新版本
下面是我在默认5.6版本上添加5.2和7.3.8的步骤。
1 -下载php TS版本;
V7.3.8(最新版本):https://windows.php.net/download/ V5.2: https://www.apachelounge.com/viewtopic.php?t=7349
2 -按顺序提取到c:\xampp\php738和c:\xampp\php52文件夹
3 -添加这些行到httpd-xamp .conf(或httpd.conf)的底部;
***重要注意:你不应该使用脚本别名作为你的目标文件夹名称, 它们必须是不同的。(例如/php7x可以,/php7不行)
PHP 7.3.8用于文件夹D: www\php7
ScriptAlias /php7x "C:/xampp/php738"
Action application/x-httpd-php7-cgi /php7x/php-cgi.exe
<Directory "C:/xampp/php738">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "D:\www\php7">
<FilesMatch "\.php$">
SetHandler application/x-httpd-php7-cgi
</FilesMatch>
</Directory>
目录D:\www\php52
ScriptAlias /phpold "C:/xampp/php52"
Action application/x-httpd-phpold-cgi /phpold/php-cgi.exe
<Directory "C:/xampp/php52">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "D:\www\php52">
<FilesMatch "\.php$">
SetHandler application/x-httpd-phpold-cgi
</FilesMatch>
</Directory>
一些有用的提示:
如果你有php5的问题。X,同时使用编写器切换终端到7.3.8 如果你想让php 7.3.8成为windows上默认的命令行php解释器,只需将php的windows环境路径更改为7.3.8文件夹路径。 不要忘记在每个版本文件夹中编辑你需要的相关php.ini confs。
作为最后的额外提示,如果您需要设置虚拟主机的任何版本,您可以使用类似的方法。 laravel vhost conf for php 7.3.8
<VirtualHost *:80>
ServerAdmin admin@laravel.local
DocumentRoot "D:\www\vhosts\laravel.local\public"
ServerName laravel.local
<FilesMatch "\.php$">
SetHandler application/x-httpd-php7-cgi # escape for default php version
#SetHandler application/x-httpd-phpold-cgi # unescape for php 5.2
</FilesMatch>
ErrorLog "logs/laravel.local.log"
CustomLog "logs/laravel.local.log" combined
感谢@Munim Munna的详细回答,我想分享一个坚实的样本和上面的重要通知。