在我的 Windows 中同时运行 php 5.x 和 php 7.0 [英] Running php 5.x and php 7.0 at the same time in my windows

查看:11
本文介绍了在我的 Windows 中同时运行 php 5.x 和 php 7.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的 php 项目制作了一个备份文件,然后卸载旧的 xampp(php 5.x.x).之后,我尝试安装最新的 xampp 版本(php 7.0.1) 并将旧 xampp 中的备份文件放入包括其数据库的新 xampp 中运行.问题是,当我尝试运行我的旧文件时,我遇到了很多错误.似乎有很多代码对于新的 php 版本已经过时了.再次运行旧文件的最佳方法是什么?我想我可能会重新安装旧的 xampp,但我也想使用最新的 php 版本.理想的做法是什么?我已经阅读了一些关于它的文章,但我没有找到一个明确的解释.请帮忙.

I made a backup file for my php projects then uninstall the old xampp(php 5.x.x). After that, I try to install the latest xampp version(php 7.0.1) and put the backup file from my old xampp to run into the new one including its database. The problem is that, when I try to run my old file I encounter lot of errors. It seems there are lots of code that are obsolete to the new php version. What is the best way to run my old file again ? I think I might reinstall the old xampp but I also want to use the latest php version. What is the ideal thing to do ? I have read some article about it, but I didn't found a clear explanation about this. Please help.

推荐答案

我找到了一个解决方案,可以快速从5.67.0更改PHP的版本7.1 只需安装一个 Xampp.

I found a solution to quickly change the version of PHP from 5.6, 7.0 and 7.1 with only one Xampp installation.

我目前正在使用它在Windows本地开发没有问题,数据库保持不变,Apache httpd-vhosts.conf配置文件:这允许快速更改P​​HP版本并且很容易.

I'm currently using it to develop locally with Windows without having problems, the database remains unchanged and also the Apache httpd-vhosts.conf configuration file: this allows the PHP version to be changed quickly and easily.

从 ApacheFriends 官方网站下载最新 3 个版本的 Xampp(控制面板 3.2.2)windows 便携版:

From the official ApacheFriends website download the latest 3 versions of Xampp (Control Panel 3.2.2) for windows portable version:

xampp-portable-win32-7.1.7-0-VC14.zip
xampp-portable-win32-7.0.21-0-VC14.zip
xampp-portable-win32-5.6.31-0-VC11.zip

xampp-portable-win32-7.1.7-0-VC14.zip
xampp-portable-win32-7.0.21-0-VC14.zip
xampp-portable-win32-5.6.31-0-VC11.zip

将Xampp win32-7.1.7版本解压到C: 
C:xamppphp 文件夹重命名为 C:xamppphp-7.1.7

Unzip the Xampp win32-7.1.7 version in C: 
Rename the C:xamppphp folder to C:xamppphp-7.1.7

来自Xampp win32-7.0.21版本
xamppphp 文件夹解压到 C:xamppphp
然后将其重命名为 C:xamppphp-7.0.21

From Xampp win32-7.0.21 version
extract the xamppphp folder to C:xamppphp
and then rename it to C:xamppphp-7.0.21

来自Xampp win32-5.6.31版本
xamppphp 文件夹解压到 C:xamppphp
然后将其重命名为 C:xamppphp-5.6.31

From Xampp win32-5.6.31 version
extract the xamppphp folder to C:xamppphp
and then rename it to C:xamppphp-5.6.31

转到 C:xamppapacheconfextra
并重命名 httpd-xampp-php-7.conf

从Xampp win32-5.6.31版本解压xamppapacheconfextrahttpd-xampp.conf文件到C:xamppapacheconfextrahttpd-xampp.conf
然后将其重命名为 httpd-xampp-php-5.conf

From Xampp win32-5.6.31 version extract the xamppapacheconfextrahttpd-xampp.conf file to C:xamppapacheconfextrahttpd-xampp.conf
and then rename it to httpd-xampp-php-5.conf

C:xampp** 中创建一个名为**php-switch"的新文件夹并创建 3 个 .bat 文件,每个文件用于您要管理的每个 PHP 版本.

In C:xampp** create a new folder with name "**php-switch" and create 3 .bat files, one for each PHP version that you want to manage.

这是要包含在各个文件中的代码:

Here is the code to include in the individual files:

set-php-5.6.bat

set-php-5.6.bat

@echo off
rmdir C:xamppphp
mklink /J C:xamppphp C:xamppphp-5.6.31
del C:xamppapacheconfextrahttpd-xampp.conf
copy C:xamppapacheconfextrahttpd-xampp-php-5.conf C:xamppapacheconfextrahttpd-xampp.conf 
echo The version of PHP 5.6.31 is set
pause

set-php-7.0.bat

set-php-7.0.bat

@echo off
rmdir C:xamppphp
mklink /J C:xamppphp C:xamppphp-7.0.21
del C:xamppapacheconfextrahttpd-xampp.conf
copy C:xamppapacheconfextrahttpd-xampp-php-7.conf C:xamppapacheconfextrahttpd-xampp.conf
echo The version of PHP 7.0.21 is set
pause

set-php-7.1.bat

set-php-7.1.bat

@echo off
rmdir C:xamppphp
mklink /J C:xamppphp C:xamppphp-7.1.7
del C:xamppapacheconfextrahttpd-xampp.conf
copy C:xamppapacheconfextrahttpd-xampp-php-7.conf C:xamppapacheconfextrahttpd-xampp.conf
echo The version of PHP 7.1.7 is set
pause

好吧,是时候测试一切是否正常了:
- 运行您要设置的 PHP 版本的 .bat 文件(例如 set-php-7.1.bat)
- 启动 Xampp 控制面板并启动 Apache
- 前往 http://localhost/dashboard/phpinfo.php 页面查看本地 PHP 实时版本

Well, it's time to test if everything works:
- run the .bat file for the PHP version you want to set (eg set-php-7.1.bat)
- start Xampp Control Panel and start Apache
- check the PHP live version locally by going to the http://localhost/dashboard/phpinfo.php page

更改 PHP 版本:
- 从 Xampp 控制面板停止 Apache
- 运行 .bat 文件以更改 PHP 版本(例如 set-php-5.6.bat)
- 从 Xampp 控制面板启动 Apache
- 前往 http://localhost/dashboard/phpinfo.php 页面查看本地 PHP 实时版本

To change PHP version:
- from Xampp Control Panel stop Apache
- run .bat files to change PHP version (eg set-php-5.6.bat)
- from Xampp Control Panel start Apache
- check the PHP live version locally by going to the http://localhost/dashboard/phpinfo.php page

注意事项:

与在单独的文件夹中安装多个版本的 Xampp 相比,此解决方案允许只有一个 Xampp 控制面板,并且只更改 PHP 版本,同时保持 C:xamppapacheconfextrahttpd-vhosts.conf 文件中的数据库和任何 Apache 自定义项不变.

Compared to installing multiple versions of Xampp in separate folders, this solution allows to have only one Xampp Control Panel and only change the PHP version while keeping the batabase and any Apache customizations in the C:xamppapacheconfextrahttpd-vhosts.conf file unchanged.

此外,此解决方案可以在 Linux 和 Mac 上使用,只需将 .bat 文件(及其命令)更改为 Linux 的 .sh 和 Mac 文件的 .command(我个人没有在 Linux 和 Mac 上运行测试,但我期望它完成没有任何问题).

Also, this solution can work with Linux and Mac by simply changing the .bat files (and their commands) to .sh for Linux and .command for Mac files (I personally did not run tests on Linux and Mac, but I expect it to be done without any problems).

这篇关于在我的 Windows 中同时运行 php 5.x 和 php 7.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆