我们使用PHP 7.0运行XAMPP,因为我们的新产品需要PHP 7。

但也有一些旧的项目使用mysql_connect等函数。这些在PHP 7.0中被删除。

那么,是否有一种方法可以轻松地在XAMPP中更改PHP版本?

注意:请不要建议将旧项目升级到与新版本兼容,因为我无法做到这一点 这些决定是我作为开发人员(只是一名员工)无法得到的。


当前回答

您可以有两个不同版本的XAMPP。

Download those files from https://www.apachefriends.org/download.html and install into a directory of your choice, for example in C:\5.6.31\xampp and C:\7.1.18\xampp. After every installation go to installed directory (ex. C:\5.6.31\xampp, C:\7.1.18\xampp) and start the "setup_xampp.bat" and you should see something like this. You can make shortcuts of "xampp-control.exe" on your desktop (right click on "xampp-control.exe" Send to -> Desktop) and rename shortcuts for ex. "xampp 5.6.31" and "xampp 7.1.8". Start XAMPP control panel with double-click on "xampp-control.exe" or previously created shortcut and start Apache and MySQL servers. To test installiation open your browser and type 127.0.0.1 or localhost in the location bar. You should see XAMPP start screen. Do not open more then one XAMPP control panel. XAMPP uninstall? Simply remove the "xampp" Directory. But before please shutdown the apache and mysql. That's all. You can use different php versions opening corresponding XAMPP control panel.

其他回答

你可以像我一样下载并安装两个不同的xampps:(第一个是php7,第二个是php5)

如果你不想这样做,我建议你使用wamp并像这里显示的那样更改版本。

你可以下载你需要的任何版本的PHP,并把它们放在自己的目录中。

c: \ php5 \

c: \ php7 \

你所需要做的就是告诉你的web服务器(Apache)要使用哪个版本的PHP,这是通过加载适当的模块来完成的。在Apache中,你可以通过找到httpd.conf文件,然后编辑相应的行来做到这一点:

LoadModule php7_module c:\php7\libphp7.so

当然,你必须找出正确的路径——这只是为了说明。

保存httpd.conf并重新启动服务器。注意,如果您不重新启动它,更改将不会生效。

没有GUI开关可以做到这一点,你需要编辑.conf文件,然后重新启动Apache。这样做只需要几秒钟,你甚至可以注释掉一个版本,这样“切换”只需要几次按键,例如。

使用PHP 5:

LoadModule php5_module c:\php5\libphp5.so
#LoadModule php7_module c:\php7\libphp7.so

使用PHP 7:

#LoadModule php5_module c:\php5\libphp5.so
LoadModule php7_module c:\php7\libphp7.so

您不需要多个版本的XAMPP,也不需要双启动,也不需要使用不同的机器,也不需要任何其他提出复杂解决方案的“解决方案”。OP希望使用XAMPP,并告诉它使用哪个版本的PHP。这是最快和最有效的方法,并且只需要安装一次XAMPP。

Edit 1-Nov-2017: Apparently some people are saying there's no .so files on Windows. The answer I gave was adapted from how I have things set up on my Mac (which does use .so files instead of .dll). The principle of the answer however is still exactly correct. You are using Apache's configuration file, httpd.conf to specify where the PHP module (.so or .dll) is located on your system. So the only difference for Windows would be the file name and/or path location. The answer I've given is also correct for a vanilla installation of Apache/PHP (without XAMPP at all).

也许有点晚了,但我正在使用批处理重命名PHP文件夹(对我几年前发现的phpswitch略有修改)。

将不同的文件夹复制到XAMPP安装中。每个PHP文件夹(活动文件夹除外)接收版本号作为后缀(例如。php_5.6.32)。在所有PHP文件夹中,创建一个文件(PHP_VERSION),其中只包含相应的版本号,因此Script可以获取该信息。但这些都在自述书中描述了。

从PHP7开始,httpd-xamp .conf加载php7ts.dll而不是php5ts.dll。因此,我必须扩展脚本(PHPSwitch.php),以遵循相同的方法重命名这些配置文件。

    $renameCur = new PHPSwitch_Rename($currInst['path'], $this->_cfg['phpInstallationsPath'] . $this->_cfg['phpDirName'] . '_' . $currInst['version']);
    $renameNew = new PHPSwitch_Rename($newInst['path'], $this->_cfg['phpInstallationsPath'] . $this->_cfg['phpDirName']);

    $apache_curent      = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp.conf";
    $apache_curent_rename   = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp_".$currInst['version'].".conf";
    $apache_new             = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp_".$newInst['version'].".conf";
    $apache_new_rename      = $this->_cfg["phpInstallationsPath"]."apache/conf/extra/httpd-xampp.conf";

    $renameCur_apache_conf = new PHPSwitch_Rename($apache_curent, $apache_curent_rename);
    $renameNew_apache_conf = new PHPSwitch_Rename($apache_new, $apache_new_rename);

    $transaction = new PHPSwitch_Rename_Transaction();
    $transaction->add($renameCur);
    $transaction->add($renameNew);
    $transaction->add($renameCur_apache_conf);
    $transaction->add($renameNew_apache_conf);

除非它必须是绝对的XAMPP,否则您可以尝试使用WAMP得到您想要的东西。 WAMP几乎是相同的东西,只是包装不同。

一旦你安装了它,你可以在这里切换php版本:

您可以根据需要安装任意版本的PHP。

下面是具体的操作步骤。

点击这里:WAMP下载

然后选择你的基础服务器,例如最新的php7。

然后,当WAMP 3安装完成后,进入文件夹:addons并选择你想要的php版本。他们提供了从php 5.3.29开始的php版本,它应该与mysql_connect一起工作。

要安装插件,在安装过程中(双击exe文件)只需指向安装WAMP 3的文件夹。

然后您可以使用其他文件夹的内容,如:应用程序等,以添加更多的功能

所有东西都是接口的,所以您可以专注于编码,而不是破坏您的环境。

这可能是这个问题最不具技术性的答案,但也是最容易实现的。

如果你有两个驱动器,比如C:和D:,你可以在两个不同的php版本的驱动器上安装XAMPP的单独实例。这花了我不到10分钟的时间,是最不容易出错的。

我只是为xampp-control.exe创建了两个桌面快捷方式,并以它们的php版本命名快捷方式。我希望这能帮助像我这样喜欢快速而肮脏的解决方案的人。