有没有办法在 XAMPP 中使用两个 PHP 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45790160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:09:08  来源:igfitidea点击:

Is there way to use two PHP versions in XAMPP?

phpxampp

提问by I am the Most Stupid Person

We are running XAMPP with PHP 7.0 because our new products requires PHP 7.

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

But there are old projects which use functions like mysql_connect, etc. Those are removed in PHP 7.0.

但是有些旧项目使用了诸如mysql_connect, 之类的函数。这些在 PHP 7.0 中被删除了。

So, is there a way to easily change PHP versions in XAMPP?

那么,有没有办法在 XAMPP 中轻松更改 PHP 版本?

Note: Please don't suggest to upgrade old project to compatible with new versions because I am not in a position to do it because of that decisions I can't get as a developer (just an employee).

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

回答by Munim Munna

Why switch between PHP versions when you can use multiple PHP versionat a same time with a single xampp installation? With a single xampp installation, you have 2 options:

当您可以通过单个 xampp 安装同时使用多个PHP 版本时,为什么要在 PHP 版本之间切换?使用单个 xampp 安装,您有 2 个选项:

  1. Run an older PHP version for only the directory of your old project:This will serve the purpose most of the time, you may have one or two old projects that you intend to run with older PHP version. Just configure xampp to run older PHP version only for those project directories.

  2. Run an older PHP version on a separate port of xampp:Sometimes you may be upgrading and old project to latest PHP version when you need to run the same project on new and older PHP version back and forth. Then you can set an older PHP version on a different port (say 8056) so when you go to http://localhost/any_project/xampp runs PHP 7 and when you go to http://localhost:8056/any_project/xampp runs PHP 5.6.

  3. Run an older PHP version on a virtualhost:You can create a virtualhost like localhost56 to run PHP 5.6 while you can use PHP 7 on localhost.

  1. 仅为旧项目的目录运行旧版本的 PHP:这在大多数情况下都适用,您可能有一个或两个旧项目打算使用旧版本的 PHP 运行。只需将 xampp 配置为仅对那些项目目录运行旧的 PHP 版本。

  2. 在单独的 xampp 端口上运行较旧的 PHP 版本:有时,当您需要在新旧 PHP 版本上来回运行同一项目时,您可能会将旧项目升级到最新的 PHP 版本。然后你可以在不同的端口(比如 8056)上设置一个旧的 PHP 版本,这样当你去http://localhost/any_project/xampp 时运行 PHP 7,当你去http://localhost:8056/any_project/xampp 时运行 PHP 5.6。

  3. 在虚拟主机上运行较旧的 PHP 版本:您可以创建一个像 localhost56 这样的虚拟主机来运行 PHP 5.6,而您可以在 localhost 上使用 PHP 7。

Lets set it up.

让我们设置它。

Step 1:Download PHP

第 1 步:下载 PHP

So you have PHP 7 running under xampp, you want to add an older PHP version to it, say PHP 5.6. Download the nts (Non Thread Safe) version of PHP zip archive from php.net(see archivefor older versions) and extract the files under c:\xampp\php56. The thread safe version does not include php-cgi.exe.

所以你有 PHP 7 在 xampp 下运行,你想向它添加一个旧的 PHP 版本,比如 PHP 5.6。从php.net下载 nts(非线程安全)版本的 PHP zip 存档(请参阅旧版本的存档)并在c:\xampp\php56. 线程安全版本不包含 php-cgi.exe。

Step 2:Configure php.ini

第 2 步:配置php.ini

Open c:\xampp\php56\php.inifile in notepad. If the file does not exist copy php.ini-developmentto php.iniand open it in notepad. Then uncomment the following line:

c:\xampp\php56\php.ini在记事本中打开文件。如果该文件不存在复制php.ini-developmentphp.ini并在记事本打开它。然后取消注释以下行:

extension_dir = "ext"

Step 3:Configure apache

第三步:配置apache

Open xampp control panel, click config button for apache, and click Apache (httpd-xampp.conf). A text file will open up put the following settings at the bottom of the file:

打开 xampp 控制面板,点击 apache 的配置按钮,然后点击Apache (httpd-xampp.conf)。将打开一个文本文件,将以下设置放在文件底部:

ScriptAlias /php56 "C:/xampp/php56"
Action application/x-httpd-php56-cgi /php56/php-cgi.exe
<Directory "C:/xampp/php56">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

Note:You can add more versions of PHP to your xampp installation following step 1 to 3 if you want.

注意:如果需要,您可以按照步骤 1 到 3 将更多版本的 PHP 添加到您的 xampp 安装中。

Step 4 (option 1):[Add Directories to run specific PHP version]

第 4 步(选项 1):[添加目录以运行特定 PHP 版本]

Now you can set directories that will run in PHP 5.6. Just add the following at the bottom of the config file to set directories.

现在您可以设置将在 PHP 5.6 中运行的目录。只需在配置文件的底部添加以下内容即可设置目录。

<Directory "C:\xampp\htdocs\my_old_project1">
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</Directory>

<Directory "C:\xampp\htdocs\my_old_project2">
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</Directory>

Step 4 (option 2):[Run older PHP version on a separate port]

第 4 步(选项 2):[在单独的端口上运行较旧的 PHP 版本]

Now to to set PHP v5.6 to port 8056 add the following code to the bottom of the config file.

现在要将 PHP v5.6 设置为端口 8056,请将以下代码添加到配置文件的底部。

Listen 8056
<VirtualHost *:8056>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</VirtualHost>

Step 4 (option 3):[Run an older PHP version on a virtualhost]

第 4 步(选项 3):[在虚拟主机上运行较旧的 PHP 版本]

To create a virtualhost (localhost56) on a directory (htdocs56) to use PHP v5.6 on http://localhost56, create directory htdocs56 at your desired location and add localhost56 to your hosts file (see how), then add the following code to the bottom of httpd-xampp.conf file.

要在目录 (htdocs56) 上创建虚拟主机 (localhost56) 以在http://localhost56上使用 PHP v5.6 ,请在所需位置创建目录 htdocs56 并将 localhost56 添加到您的主机文件(查看方法),然后添加以下代码到 httpd-xampp.conf 文件的底部。

<VirtualHost localhost56:80>
    DocumentRoot "C:\xampp\htdocs56"
    ServerName localhost56
    <Directory "C:\xampp\htdocs56">
        Require all granted    
    </Directory>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</VirtualHost>

Finish:Save and Restart Apache

完成:保存并重启Apache

Save and close the config file, Restart apache from xampp control panel. If you went for option 2 you can see the additional port(8056) listed in your xampp control panel.

保存并关闭配置文件,从 xampp 控制面板重新启动 apache。如果您选择选项 2,您可以看到 xampp 控制面板中列出的附加端口 (8056)。

enter image description here

在此处输入图片说明

Update for Error:
malformed header from script 'php-cgi.exe': Bad header

更新错误:
来自脚本“php-cgi.exe”的格式错误的标题:错误的标题

If you encounter the above error, open httpd-xampp.confagain and comment out the following line with a leading # (hash character).

如果遇到上述错误,请httpd-xampp.conf再次打开并用前导 #(哈希字符)注释掉以下行。

SetEnv PHPRC "\path\to\xampp\php"

回答by Andy

You can download whatever versions of PHP you need and place them into their own directories, e.g.

您可以下载您需要的任何版本的 PHP 并将它们放入自己的目录中,例如

c:\php5\

c:\php5\

c:\php7\

c:\php7\

All you need to do is tell your web server (Apache) which version of PHP to use, which you do by loading the appropriate module. In Apache you can do this by finding the file httpd.confand then editing the appropriate line:

您需要做的就是告诉您的 Web 服务器 (Apache) 要使用哪个版本的 PHP,您可以通过加载适当的模块来执行该操作。在 Apache 中,您可以通过查找文件httpd.conf然后编辑相应的行来完成此操作:

LoadModule php7_module c:\php7\libphp7.so

LoadModule php7_module c:\php7\libphp7.so

You'll have to figure out the correct paths of course - this is just for illustration.

当然,您必须找出正确的路径 - 这仅用于说明。

Save httpd.confand restart your server. Note, if you don't restart it, the changes won't take effect.

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

There's no GUI switch to be able to do this, you need to edit the .conffile and then restart Apache. Doing this only takes a couple of seconds and you could even comment out a version so "switching" only takes a couple of keystrokes, e.g.

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

Use PHP 5:

使用 PHP 5:

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

Use PHP 7:

使用 PHP 7:

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

You do not need multiple versions of XAMPP, or to dual boot, or use a different machine, or any of the other "solutions" that have suggested convoluted workarounds. The OP wants to use XAMPP and tell it which version of PHP to use. This is the quickest and most efficient way of doing it, and only requires one XAMPP installation.

您不需要多个版本的 XAMPP,或者双启动,或者使用不同的机器,或者任何其他建议复杂变通方法的“解决方案”。OP 想要使用 XAMPP 并告诉它使用哪个版本的 PHP。这是最快和最有效的方法,只需要安装一个 XAMPP。

Edit 1-Nov-2017:Apparently some people are saying there's no .sofiles on Windows. The answer I gave was adapted from how I have things set up on my Mac (which does use .sofiles instead of .dll). The principle of the answer however is still exactly correct. You are using Apache's configuration file, httpd.confto specify wherethe PHP module (.soor .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).

2017 年 11 月 1 日编辑:显然有些人说.soWindows上没有文件。我给出的答案改编自我如何在我的 Mac 上设置东西(它确实使用.so文件而不是.dll)。然而,答案的原则仍然是完全正确的。您正在使用Apache的配置文件,httpd.conf指定其中的PHP模块(.so.dll)位于您的系统上。因此,Windows 的唯一区别是文件名和/或路径位置。我给出的答案对于 Apache/PHP 的 vanilla 安装也是正确的(根本没有 XAMPP)。

回答by Maulik Gangani

You can downloadand install two different xampps like I do: (first is php7 second is php5) enter image description here

您可以像我一样下载并安装两个不同的 xampps:(第一个是 php7,第二个是 php5) 在此处输入图片说明

and if you don't want to do that, I suggest you use wamp and change versions like shown here.

如果您不想这样做,我建议您使用 wamp 并更改此处所示的版本。

回答by Nigel Ren

I would recommend using Docker, this allows you to split the environment into various components and mix and match the ones you want at any time.

我建议使用 Docker,这允许您将环境拆分为各种组件,并随时混合和匹配您想要的组件。

Docker will allow you to run one container with MySQL, another with PHP. As they are separate images you can have two containers, one PHP 5 another PHP 7, you start up which ever one you wish and port 80 can be mapped to both containers.

Docker 将允许您使用 MySQL 运行一个容器,使用 PHP 运行另一个容器。由于它们是单独的映像,您可以拥有两个容器,一个 PHP 5 另一个 PHP 7,您可以启动任意一个,并且端口 80 可以映射到两个容器。

https://hub.docker.comhas a wide range of preconfigured images which you can install and run without much hassle.

https://hub.docker.com拥有广泛的预配置映像,您可以轻松安装和运行这些映像。

I've also added portaineras an image, which allows you to manage the various aspects of your docker setup - from within a docker image (I did start this container on startup to save me having to use the command line). It doesn't do everything for you and sometimes it's easier to configure and launch the images for the first time from the command line, but once setup you can start and stop them through a web interface.

我还添加了portainer作为图像,它允许您从 docker 图像中管理 docker 设置的各个方面(我确实在启动时启动了这个容器,以免我不得不使用命令行)。它并不能为您完成所有工作,有时首次从命令行配置和启动图像会更容易,但是一旦设置好,您就可以通过 Web 界面启动和停止它们。

It's also possible to run both containers at the same time and map separate ports to each. So port 80 can be mapped to PHP 5 and 81 to PHP 81 (Or PHP 7 if your watching this in 2017).

也可以同时运行两个容器并将单独的端口映射到每个容器。所以端口 80 可以映射到 PHP 5 和 81 到 PHP 81(或者 PHP 7,如果你在 2017 年看这个)。

There are various tutorials on how to install Docker( https://docs.docker.com/engine/installation/) and loads of other 'how to' type things. Try http://www.masterzendframework.com/docker-development-environment/for a development environment configuration.

有各种关于如何安装 Docker(https://docs.docker.com/engine/installation/)的教程和大量其他“如何”类型的东西。尝试http://www.masterzendframework.com/docker-development-environment/进行开发环境配置。

回答by ArtisticPhoenix

I use Uniserver.

我使用 Uniserver。

It has this feature built in.

它内置了此功能。

http://www.uniformserver.com/

http://www.uniformserver.com/

It's that simple.

就这么简单。

The Uniform Server is a free lightweight WAMP server solution for Windows. Less than 24MB, modular design, includes the latest versions of Apache2, Perl5, PHP (switch between PHP53, PHP54, PHP55 or PHP56), MySQL5 or MariaDB5, phpMyAdmin or Adminer4. No installation required! No registry dust! Just unpack and fire up!

Uniform Server 是适用于 Windows 的免费轻量级 WAMP 服务器解决方案。小于24MB,模块化设计,包含最新版本的Apache2、Perl5、PHP(在PHP53、PHP54、PHP55或PHP56之间切换)、MySQL5或MariaDB5、phpMyAdmin或Adminer4。无需安装!没有注册表灰尘!只需打开包装并启动!

It even runs off a flash drive. Has cron emulation, support for perl, mariaDB, a couple versions of Mysql, filezilla server and a few other things.

它甚至运行在闪存驱动器上。具有 cron 仿真,支持 perl、mariaDB、几个版本的 Mysql、filezilla 服务器和其他一些东西。

enter image description here

在此处输入图片说明

回答by Erdin? ?orbac?

I am working on a ten years old project at work. So 5.6 is my default. There are also older small projects which only works with 5.2 and I also want to work on new versions for my personal projects with 7.3.8

我正在工作一个十年前的项目。所以 5.6 是我的默认值。还有一些旧的小项目仅适用于 5.2,我也想为我的个人项目使用 7.3.8 开发新版本

Here is what I did to add 5.2 and 7.3.8 on default 5.6 version.

这是我在默认 5.6 版本上添加 5.2 和 7.3.8 所做的工作。

1 - Downloaded php TS versions ;

1 - 下载 php TS 版本;

  • v7.3.8(最新):https://windows.php.net/download/

  • v5.2:https://www.apachelounge.com/viewtopic.php ?t =7349

2 - Extracted to c:\xampp\php738 and c:\xampp\php52 folder in order

2 - 依次解压到 c:\xampp\php738 和 c:\xampp\php52 文件夹

3 - Added these lines to the bottom of httpd-xampp.conf (or httpd.conf) ;

3 - 将这些行添加到 httpd-xampp.conf(或 httpd.conf)的底部;

*** IMPORTANT NOTICE : You should NOT use script alias name as your target folder name, they must be different. (for instance /php7x is ok , /php7 is not)

*** 重要提示:您不应使用脚本别名作为目标文件夹名称,它们必须不同。(例如 /php7x 可以,/php7 不是)

PHP 7.3.8 for folder D:\www\php7

文件夹 D:\www\php7 的 PHP 7.3.8

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>

PHP 5.2 for folder D:\www\php52

文件夹 D:\www\php52 的 PHP 5.2

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>

Some helpful notes :

一些有用的注意事项:

  • If you have troubles with php5.x while using composer switch terminal to 7.3.8
  • If you want to make php 7.3.8 your default command line php interpreter on windows just change your windows environment path for php to the 7.3.8 folder path.
  • Don't forget to edit your relevant php.ini confs as you need in each version folder.
  • 如果您在使用 composer 将终端切换到 7.3.8 时遇到 php5.x 的问题
  • 如果您想让 php 7.3.8 成为 Windows 上的默认命令行 php 解释器,只需将 php 的 Windows 环境路径更改为 7.3.8 文件夹路径。
  • 不要忘记在每个版本文件夹中根据需要编辑相关的 php.ini confs。

And as a last bonus note , if you need to set a virtual host with any of versions you can use similar approach. A sample laravel vhost conf for php 7.3.8;

作为最后的附加说明,如果您需要使用任何版本设置虚拟主机,您可以使用类似的方法。php 7.3.8 的示例 laravel vhost conf;

<VirtualHost *:80>
ServerAdmin [email protected]
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

Thanks to @Munim Munna for detailed answer, I wanted to share a solid sample with the important notice above.

感谢@Munim Munna 的详细回答,我想与上面的重要通知分享一个可靠的样本。

回答by og1842

You can have two different versions of XAMPP.

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

  • Download those files from https://www.apachefriends.org/download.htmland 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.
  • https://www.apachefriends.org/download.html下载这些文件并安装到您选择的目录中,例如 C:\5.6.31\xampp 和 C:\7.1.18\xampp。
  • 每次安装后,转到安装目录(例如 C:\5.6.31\xampp、C:\7.1.18\xampp)并启动“setup_xampp.bat”,您应该会看到类似 这样的内容。
  • 您可以在桌面上制作“xampp-control.exe”的快捷方式(右键单击“xampp-control.exe”发送到->桌面)并为ex重命名快捷方式。“xampp 5.6.31”和“xampp 7.1.8”。
  • 双击“xampp-control.exe”或之前创建的快捷方式启动 XAMPP 控制面板,然后启动 Apache 和 MySQL 服务器。
  • 要测试安装,请打开浏览器并在位置栏中键入 127.0.0.1 或 localhost。您应该会看到 XAMPP 启动屏幕。
  • 不要打开多个 XAMPP 控制面板。
  • XAMPP卸载?只需删除“xampp”目录。但在此之前请关闭 apache 和 mysql。
  • 就这样。您可以使用不同的 php 版本打开相应的 XAMPP 控制面板。

回答by Jeffz

Unless it has to be absolutely and definitely XAMPP, you can try to get what you want with WAMP. WAMP is pretty much the same thing in different package.

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

Once you have it installed, you can just switch between php versions here:

安装后,您可以在此处在 php 版本之间切换:

enter image description here

在此处输入图片说明

You can install as many versions of PHP as you need.

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

Here's how it is done in detail.

以下是它的详细操作方法。

Just go here: WAMP download

去这里:WAMP下载

Then select your base server, e.g. latest with php7.

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

Then, when WAMP 3 is installed, go to folder: addonsand select php version (or versions) you are after. They offer php flavors starting from php 5.3.29, which should work with mysql_connect.

然后,安装 WAMP 3 后,转到文件夹:插件并选择您想要的 php 版本(或多个版本)。他们提供从 php 5.3.29 开始的 php 风格,应该与 mysql_connect 一起使用。

To install addon, during installation (double click exe file) just point to folder where you have your WAMP 3 installed.

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

Then you can use content of other folders, like: applicationsetc. to add more functionality

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

Everything's interfaced, so you can concentrate on coding and not hacking your environment.

一切都是接口,因此您可以专注于编码而不是侵入您的环境。

回答by Shuvro

Yes you can. I assume you have a xampp already installed. So,

是的你可以。我假设您已经安装了 xampp。所以,

  • Close all xampp instances. Using task manager stop apache and mysqld.
  • Then rename the xampp to xampp1 or something after xampp name.
  • Now Download the other xampp version. Create a folder name xampp only. Install the downloaded xampp there.
  • Now depending on the xampp version of your requirement, just rename the target folder to xampp only and other folder to different name.
  • 关闭所有 xampp 实例。使用任务管理器停止 apache 和 mysqld。
  • 然后将 xampp 重命名为 xampp1 或 xampp 名称之后的其他名称。
  • 现在下载另一个 xampp 版本。仅创建文件夹名称 xampp。在那里安装下载的 xampp。
  • 现在,根据您要求的 xampp 版本,只需将目标文件夹重命名为 xampp only,将其他文件夹重命名为不同的名称。

That's how I am working with multiple xampp installed

这就是我安装多个 xampp 的方式

回答by maxime_039

It's possible to have multiple versions of PHP set up with a single XAMPP installation. The instructions below are working for Windows.

可以使用单个 XAMPP 安装设置多个版本的 PHP。以下说明适用于 Windows。

  1. Install the latest XAMPP version for Windows (in my case it was with PHP 7.1)
  2. Make sure that Apache is not running from XAMPP Control Panel
  3. Rename the php directory in XAMPP install directory, such as C:\xampp\phpbecome C:\xampp\php-7.1.11.
  4. Download the version of PHP you'd like to run in addition (Eg: PHP 5.4.45)
  5. Move the php directory from the version you downloaded to XAMPP install directory. Rename it so it includes the PHP version. Such as C:\xampp\php-5.4.45.
  1. 安装适用于 Windows 的最新 XAMPP 版本(在我的情况下是使用 PHP 7.1)
  2. 确保 Apache 没有从 XAMPP 控制面板运行
  3. 重命名XAMPP的PHP目录的安装目录,如C:\xampp\php成为C:\xampp\php-7.1.11
  4. 下载您想另外运行的 PHP 版本(例如:PHP 5.4.45
  5. 将 php 目录从您下载的版本移动到 XAMPP 安装目录。重命名它,使其包含 PHP 版本。比如C:\xampp\php-5.4.45

Now you need to edit XAMPP and Apache configuration :

现在您需要编辑 XAMPP 和 Apache 配置:

  1. In C:\xampp\apache\conf\httpd.conf, locate the XAMPP settings for PHP, you should change it to something such as :
  1. 在 中C:\xampp\apache\conf\httpd.conf,找到 PHP 的 XAMPP 设置,您应该将其更改为诸如:

Where you have to comment (with #) the other PHP versions so only one Includewill be interpreted at the time.

您必须对#其他 PHP 版本进行注释(使用),因此当时Include只会解释一个。

#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"
  1. Now in C:\xampp\apache\conf\extradirectory rename httpd-xampp.confto httpd-xampp.conf.7.1and 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.

  2. Edit httpd-xampp.conf.5.4.45and httpd-xampp.conf.7.1and replace there all the reference to the phpdirectory with the new php-X.Xversion. There are at least 10 changes to be made here for each file.

  3. 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.iniwhere you will replace the path of the php directory for include_path, browscap, error_log, extension_dir..

  1. 现在在C:\xampp\apache\conf\extra目录中重命名httpd-xampp.confhttpd-xampp.conf.7.1并添加一个新的配置文件httpd-xampp.conf.5.4.45。就我而言,我复制了另一个 XAMPP for php 5.5 安装的 conf 文件,因为每个版本的语法可能略有不同。

  2. 使用新版本编辑httpd-xampp.conf.5.4.45httpd-xampp.conf.7.1替换对php目录的所有引用php-X.X。每个文件至少要在此处进行 10 次更改。

  3. 您现在需要为两个版本编辑 php.ini。例如,对于 php 7.1,编辑C:\xampp\php-7.1.11\php.ini您将替换include_pathbrowscaperror_log、的 php 目录路径的位置extension_dir

And that's it. You can now start Apache from XAMPP Control Panel. And to switch from a version to another, you need only to edit C:\xampp\apache\conf\httpd.confand change the included PHP version before restarting Apache.

就是这样。您现在可以从 XAMPP 控制面板启动 Apache。要从一个版本切换到另一个版本,您只需要C:\xampp\apache\conf\httpd.conf在重新启动 Apache 之前编辑和更改包含的 PHP 版本。