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

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

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

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


当前回答

也许有点晚了,但我正在使用批处理重命名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。所以,

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

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

我需要做同样的事情,所以我谷歌了一下,结果发现堆栈溢出,而OP也有同样的问题……所以我的发现…我尝试从不同的方向重命名文件,我的结论基本上是它花了我太长时间。所以我最终只是从这里安装了第7版:

https://www.apachefriends.org/index.html (在尝试xampp之前杀死服务并退出)

当被问到在哪里放置目录名称时,就像这样(给它一个不同的名字):

and

DONEZO !现在只要确保在来回交换之前杀死服务并退出,你就有2个无菌的XAMPP环境可以玩。

万岁!现在我真的可以去工作了!

我确实在安装magento2时遇到了同样的问题,而它需要~7.3.0,但我有7.4.1。我用这个方法降低了php的版本。

步骤1:从这里下载Php版本 https://windows.php.net/downloads/releases/archives/ 并将此版本粘贴到c:\xampp\,命名为“php71”

步骤2:设置虚拟主机环境并做一些其他更改。 转到“c:\xampp/\pache\conf\extra\httpd-vhosts.conf”,并将代码片段放在行末

<VirtualHost 127.0.0.1:80>
    DocumentRoot "C:/xampp/htdocs/magento/crashcourse/"
    ServerName magento2.test
    <Directory "C:/xampp/htdocs/magento/crashcourse/">
        Require all granted    
    </Directory>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php71-cgi
    </FilesMatch>
</VirtualHost>

转到“C:\Windows\System32\drivers\etc\hosts”,然后使用管理员权限编辑文件,然后在行末添加代码。

127.0.0.1 magento2.test

转到Apache配置文件“c:/xampp/ Apache /conf/extra/httpd-xampp.conf”,并在行末粘贴以下代码

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

现在,一切都准备好了。 去网址:http://magento2.test一切工作正常!

也许有点晚了,但我正在使用批处理重命名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);

我推荐使用Docker,它允许你将环境分成不同的组件,并在任何时候混合和匹配你想要的组件。

Docker将允许您运行一个容器与MySQL,另一个与PHP。因为它们是独立的映像,所以你可以有两个容器,一个是PHP 5,另一个是PHP 7,你可以任意启动一个,端口80可以映射到两个容器。

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

我还添加了portainer作为一个映像,它允许您从docker映像中管理docker设置的各个方面(我在启动时启动了这个容器,以避免使用命令行)。它不能为你做所有的事情,有时从命令行配置和启动图像更容易,但一旦设置好,你可以通过web界面启动和停止它们。

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

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