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

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

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

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


当前回答

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

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

其他回答

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

关闭所有xampp实例。使用任务管理器停止apache和mysqld。 然后将xampp重命名为xampp1或xampp名称之后的其他名称。 现在下载另一个xampp版本。只创建文件夹名xampp。在那里安装下载的xampp。 现在,根据您需求的xampp版本,只需将目标文件夹重命名为xampp,将其他文件夹重命名为不同的名称。

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

当您可以通过一个xampp安装同时使用多个PHP版本时,为什么要在PHP版本之间切换呢?

安装一个xampp,你有两个选择:

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 an older PHP version. Just configure xampp to run an older PHP version for only those project directories. Run an older PHP version on a separate port of xampp: Sometimes you may be upgrading an old project to the latest PHP version and at the same time you need to run the same project back and forth between the new PHP version and the old PHP version. To do this 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. 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

假设你在xampp下运行PHP 7,你想要添加一个较旧的PHP版本(比如PHP 5.6)。从php.net下载nts(非线程安全)版本的PHP压缩压缩包(参见旧版本的压缩包),并在c:\xampp\php56下解压文件。线程安全版本不包括php-cgi.exe。

步骤2:配置php.ini

在记事本中打开文件c:\xampp\php56\php.ini。如果文件不存在,将php.ini-development复制到php.ini并在记事本中打开。然后取消下面这一行的注释:

extension_dir = "ext"

同样,如果Apache配置httpd-xamp .conf中存在以下行

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

用开头的#(散列字符)注释掉它。

步骤3:配置apache

打开xampp控制面板,单击apache的config按钮,然后单击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>

注意:如果您愿意,可以在步骤1到3之后向xampp安装中添加更多版本的PHP。

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

现在可以设置将在PHP 5.6中运行的目录。只需在配置文件(步骤3中的httpd-xamp .conf)底部添加以下内容来设置目录。

<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>

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

现在要在8056端口上设置PHP v5.6,将以下代码添加到配置文件的底部(步骤3中的httpd-xamp .conf)。

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

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

要在目录(htdocs56)上创建虚拟主机(localhost56),以便在http://localhost56上使用PHP v5.6,请在所需的位置和位置创建目录htdocs56 将localhost56添加到您的hosts文件中(参见如何添加), 然后将以下代码添加到配置文件(步骤3中的httpd-xamp .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:保存并重启Apache

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

简单和最容易的步骤

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)

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

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

您可以有两个不同版本的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.