有没有办法在XAMPP中使用两个PHP版本? [英] Is there way to use two PHP versions in XAMPP?

查看:487
本文介绍了有没有办法在XAMPP中使用两个PHP版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在XAMPP和PHP 7.0上运行,因为我们的新产品需要PHP 7.

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

但是有些旧项目使用的功能类似于mysql_connect等.在PHP 7.0中已将其删除.

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

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

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

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

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

推荐答案

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

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

  1. 仅对旧项目的目录运行较旧的PHP版本: 在大多数情况下,这将达到目的,您可能会有一两个 您打算与旧PHP版本一起运行的旧项目. 只需将xampp配置为仅针对旧版本运行PHP 这些项目目录.

  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.

在xampp的单独端口上运行较旧的PHP版本:有时,您可能 需要运行时,将旧项目升级到最新的PHP版本 来回地在新旧PHP版本上进行相同的项目. 然后,您可以在其他端口上设置旧的PHP版本(例如8056) 因此,当您转到http://localhost/any_project/时,xampp会运行PHP 7 当您进入http://localhost:8056/any_project/时,xampp运行PHP 5.6.

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.

在虚拟主机上运行旧版本的PHP:您可以创建虚拟主机 例如localhost56可以运行PHP 5.6,而您可以在localhost上使用PHP 7.

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 (请参阅存档(对于较旧的版本),然后将文件提取到c:\xampp\php56下.线程安全版本不包含php-cgi.exe.

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 archive for older versions) and extract the files under c:\xampp\php56. The thread safe version does not include php-cgi.exe.

步骤2:配置php.ini

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

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

extension_dir = "ext"

第3步:配置apache

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

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:

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中将更多版本的PHP添加到xampp安装中.

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

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

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.

<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版本]

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

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

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添加到您的主机文件(查看操作方法), 然后将以下代码添加到httpd-xampp.conf文件的底部.

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.

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

完成:保存并重新启动Apache

Finish: Save and Restart Apache

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

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.

更新错误:
脚本'php-cgi.exe'中格式错误的标头:标头错误

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

如果遇到上述错误,请再次打开httpd-xampp.conf,并在下面的行中加上一个#号(哈希字符).

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

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

这篇关于有没有办法在XAMPP中使用两个PHP版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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