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

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

问题描述

我为php项目制作了一个备份文件,然后卸载了旧的xampp(php 5.x.x).之后,我尝试安装最新的xampp version(php 7.0.1)并将旧文件中的备份文件放到新文件中,包括其数据库.问题是,当我尝试运行旧文件时,遇到很多错误.似乎有很多新的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.

推荐答案

我找到了一种解决方案,可以将PHP版本从 5.6 7.0 快速更改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官方网站上下载最新版本的Xampp的3个版本(控制面板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

C:\ 
中解压缩Xampp win32-7.1.7版本. 将 C:\ xampp \ php 文件夹重命名为 C:\ xampp \ php-7.1.7

Unzip the Xampp win32-7.1.7 version in C:\ 
Rename the C:\xampp\php folder to C:\xampp\php-7.1.7

从Xampp win32-7.0.21版本开始
\ xampp \ php 文件夹提取到 C:\ xampp \ php
然后将其重命名为 C:\ xampp \ php-7.0.21

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

从Xampp win32-5.6.31版本开始
\ xampp \ php 文件夹提取到 C:\ xampp \ php
然后将其重命名为 C:\ xampp \ php-5.6.31

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

转到 C:\ xampp \ apache \ conf \ extra
并在 httpd-xampp-php-7.conf

Go to C:\xampp\apache\conf\extra
and rename the httpd-xampp.conf file in httpd-xampp-php-7.conf

从Xampp win32-5.6.31版本中将 \ xampp \ apache \ conf \ extra \ httpd-xampp.conf 文件提取到 C:\ xampp \ apache \ conf \ extra \ httpd-xampp.conf
然后将其重命名为 httpd-xampp-php-5.conf

From Xampp win32-5.6.31 version extract the \xampp\apache\conf\extra\httpd-xampp.conf file to C:\xampp\apache\conf\extra\httpd-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:\xampp\php
mklink /J C:\xampp\php C:\xampp\php-5.6.31
del C:\xampp\apache\conf\extra\httpd-xampp.conf
copy C:\xampp\apache\conf\extra\httpd-xampp-php-5.conf C:\xampp\apache\conf\extra\httpd-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:\xampp\php
mklink /J C:\xampp\php C:\xampp\php-7.0.21
del C:\xampp\apache\conf\extra\httpd-xampp.conf
copy C:\xampp\apache\conf\extra\httpd-xampp-php-7.conf C:\xampp\apache\conf\extra\httpd-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:\xampp\php
mklink /J C:\xampp\php C:\xampp\php-7.1.7
del C:\xampp\apache\conf\extra\httpd-xampp.conf
copy C:\xampp\apache\conf\extra\httpd-xampp-php-7.conf C:\xampp\apache\conf\extra\httpd-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:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf文件中的batabase和任何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:\xampp\apache\conf\extra\httpd-vhosts.conf file unchanged.

此外,只需将.bat文件(及其命令)更改为.sh(对于Linux)和.command(对于Mac文件),该解决方案就可以与Linux和Mac一起使用(我个人没有在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天全站免登陆