我们使用PHP 7.0运行XAMPP,因为我们的新产品需要PHP 7。
但也有一些旧的项目使用mysql_connect等函数。这些在PHP 7.0中被删除。
那么,是否有一种方法可以轻松地在XAMPP中更改PHP版本?
注意:请不要建议将旧项目升级到与新版本兼容,因为我无法做到这一点 这些决定是我作为开发人员(只是一名员工)无法得到的。
我们使用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);
其他回答
我正在做一个10年前的项目。5.6是我的默认值。还有一些老的小项目只能使用5.2,我还想为我的个人项目开发7.3.8的新版本
下面是我在默认5.6版本上添加5.2和7.3.8的步骤。
1 -下载php TS版本;
V7.3.8(最新版本):https://windows.php.net/download/ V5.2: https://www.apachelounge.com/viewtopic.php?t=7349
2 -按顺序提取到c:\xampp\php738和c:\xampp\php52文件夹
3 -添加这些行到httpd-xamp .conf(或httpd.conf)的底部;
***重要注意:你不应该使用脚本别名作为你的目标文件夹名称, 它们必须是不同的。(例如/php7x可以,/php7不行)
PHP 7.3.8用于文件夹D: www\php7
ScriptAlias /php7x "C:/xampp/php738"
Action application/x-httpd-php7-cgi /php7x/php-cgi.exe
<Directory "C:/xampp/php738">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "D:\www\php7">
<FilesMatch "\.php$">
SetHandler application/x-httpd-php7-cgi
</FilesMatch>
</Directory>
目录D:\www\php52
ScriptAlias /phpold "C:/xampp/php52"
Action application/x-httpd-phpold-cgi /phpold/php-cgi.exe
<Directory "C:/xampp/php52">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "D:\www\php52">
<FilesMatch "\.php$">
SetHandler application/x-httpd-phpold-cgi
</FilesMatch>
</Directory>
一些有用的提示:
如果你有php5的问题。X,同时使用编写器切换终端到7.3.8 如果你想让php 7.3.8成为windows上默认的命令行php解释器,只需将php的windows环境路径更改为7.3.8文件夹路径。 不要忘记在每个版本文件夹中编辑你需要的相关php.ini confs。
作为最后的额外提示,如果您需要设置虚拟主机的任何版本,您可以使用类似的方法。 laravel vhost conf for php 7.3.8
<VirtualHost *:80>
ServerAdmin admin@laravel.local
DocumentRoot "D:\www\vhosts\laravel.local\public"
ServerName laravel.local
<FilesMatch "\.php$">
SetHandler application/x-httpd-php7-cgi # escape for default php version
#SetHandler application/x-httpd-phpold-cgi # unescape for php 5.2
</FilesMatch>
ErrorLog "logs/laravel.local.log"
CustomLog "logs/laravel.local.log" combined
感谢@Munim Munna的详细回答,我想分享一个坚实的样本和上面的重要通知。
是的,你可以。我假设您已经安装了xampp。所以,
关闭所有xampp实例。使用任务管理器停止apache和mysqld。 然后将xampp重命名为xampp1或xampp名称之后的其他名称。 现在下载另一个xampp版本。只创建文件夹名xampp。在那里安装下载的xampp。 现在,根据您需求的xampp版本,只需将目标文件夹重命名为xampp,将其他文件夹重命名为不同的名称。
这就是我安装多个xampp的工作方式
我知道这是旧的帖子,但我想分享有一个库仍然运行mysql_connect()在PHP 7。 它通过覆盖实际函数来工作(mysql_connect()被工作在这个库上的mysqli_connect()覆盖)。
我从这个视频https://www.youtube.com/watch?v=Eqd-jJu4sQ4中找到的
希望能有所帮助
这可能是这个问题最不具技术性的答案,但也是最容易实现的。
如果你有两个驱动器,比如C:和D:,你可以在两个不同的php版本的驱动器上安装XAMPP的单独实例。这花了我不到10分钟的时间,是最不容易出错的。
我只是为xampp-control.exe创建了两个桌面快捷方式,并以它们的php版本命名快捷方式。我希望这能帮助像我这样喜欢快速而肮脏的解决方案的人。
安装一个XAMPP就可以安装多个版本的PHP。下面的说明适用于Windows。
为Windows安装最新的XAMPP版本(在我的例子中是PHP 7.1) 确保Apache没有从XAMPP控制面板运行 将XAMPP安装目录下的php目录重命名,如C:\ XAMPP \php改为C:\ XAMPP \php-7.1.11。 下载你想要运行的PHP版本(例如:PHP 5.4.45) 将php目录从您下载的版本移动到XAMPP安装目录。重命名它,使其包含PHP版本。例如C:\xampp\php-5.4.45。
现在你需要编辑XAMPP和Apache配置:
在C:\xampp\apache\conf\httpd.conf中,找到PHP的xampp设置,您应该将其更改为如下内容:
你必须注释(用#)其他的PHP版本,所以只有一个包含将被解释在同一时间。
#XAMPP settings PHP 7
Include "conf/extra/httpd-xampp.conf.7.1"
#XAMPP settings PHP 5.4.45
#Include "conf/extra/httpd-xampp.conf.5.4.45"
Now in C:\xampp\apache\conf\extra directory rename httpd-xampp.conf to httpd-xampp.conf.7.1 and add a new configuration file for httpd-xampp.conf.5.4.45. In my case, I copied the conf file of another installation of XAMPP for php 5.5 as the syntax may be slightly different for each version. Edit httpd-xampp.conf.5.4.45 and httpd-xampp.conf.7.1 and replace there all the reference to the php directory with the new php-X.X version. There are at least 10 changes to be made here for each file. You now need to edit php.ini for the two versions. For example for php 7.1, edit C:\xampp\php-7.1.11\php.ini where you will replace the path of the php directory for include_path, browscap, error_log, extension_dir..
就是这样。您现在可以从XAMPP控制面板启动Apache。要从一个版本切换到另一个版本,你只需要在重新启动apache之前编辑C:\xampp\apache\conf\httpd.conf并更改包含的PHP版本。