首页 > 学院 > 编程设计 > 正文

在 WampServer 上手工安装 PHP 的多个版本的方法分享

2020-06-27 15:43:39
字体:
来源:转载
供稿:网友
对于PHP不同版本的需求,PHP程序员都最清楚不过了。
WampServer的Version菜单(Apache、PHP、Mysql各自有一个Version菜单)上,有一个 Get More... 连接,点击它就可以到官网上下载你需要的版本,安装是自动化的,非常简单。但是,到我写本文为止,官网的PHP5.2最高为5.2.11,PHP5.3最高为5.3.1。5.2最稳定的5.2.17、5.3最新的5.3.8都没有提供,而且更新非常慢。没有我们需要的版本,怎么办?毛大爷说过一句至理名言:自己动手,丰衣足食!
手工安装新版本的PHP,只需以下步骤:
下载要安装的PHP版本。既然是用WampServer,那当然是下载Window版本的ZIP包啦:http://windows.php.net。解压到 Wamp的安装目录/bin/php/php5.2.17。这里以5.2.17为例。
进入 Wamp的安装目录/bin/php/php5.2.17 目录,从 php.ini-dist 或者 php.ini-recommended 复制一份,重命名为php.ini,适应修改php.ini配置(如extension_dir),再从php.ini复制一分,重命名为 phpForApache.ini。
从已有的版本目录中复制一份 wampserver.conf。比如我安装WampServer的时候已经有php5.3.0,在 Wamp的安装目录/bin/php/php5.3.0 目录下复制 wampserver.conf 到 Wamp的安装目录/bin/php/php5.2.17。
修改Wamp配置文件:进入 Wamp的安装目录,用IDE或记事本(最好使用行号定位的记事本,如EditPlus等)打开 wampmanager.ini,定位到 335 行,通常在这一行就是[phpVersion],如果不是,则在附近找找。复制下面一行:
Type: item; Caption: "5.3.0"; Action: multi; Actions:switchPhp5.3.0
插入到这一行前面,并修改为
Type: item; Caption: "5.2.17"; Action: multi; Actions:switchPhp5.2.17
再复制
[switchPhp5.3.0]
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "Wamp的安装目录/bin/php/php5.3.0/php-win.exe";Parameters: "switchPhpVersion.php 5.3.0";WorkingDir: "Wamp的安装目录/scripts"; Flags: waituntilterminated
Action: run; FileName: "Wamp的安装目录/bin/php/php5.3.0/php-win.exe";Parameters: "-c . refresh.php";WorkingDir: "Wamp的安装目录/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start wampapache"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;
插入这一段之前,并修改为
[switchPhp5.2.17]
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "Wamp的安装目录/bin/php/php5.3.0/php-win.exe";Parameters: "switchPhpVersion.php 5.2.17";WorkingDir: "Wamp的安装目录/scripts"; Flags: waituntilterminated
Action: run; FileName: "Wamp的安装目录/bin/php/php5.3.0/php-win.exe";Parameters: "-c . refresh.php";WorkingDir: "Wamp的安装目录/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start wampapache"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;
退出WampServer,再重启。完成。
通过这5步,即可完成PHP任意版本的安装。
另附两个文件的实例:
1. Wamp的安装目录/bin/php/php5.2.17/wampserver.conf,这实际是PHP文件

复制代码
代码如下:

<?php
$phpConf['phpIniDir'] = '.';
$phpConf['phpExeDir'] = '.';
$phpConf['phpConfFile'] = 'php.ini';
$phpConf['apache']['1.3']['LoadModuleName'] = 'php5_module';
$phpConf['apache']['1.3']['LoadModuleFile'] = 'php5apache.dll';
$phpConf['apache']['1.3']['AddModule'] = 'mod_php5.c';
$phpConf['apache']['2.0']['LoadModuleName'] = 'php5_module';
$phpConf['apache']['2.0']['LoadModuleFile'] = 'php5apache2.dll';
$phpConf['apache']['2.0']['AddModule'] = '';
$phpConf['apache']['2.2']['LoadModuleName'] = 'php5_module';
$phpConf['apache']['2.2']['LoadModuleFile'] = 'php5apache2_2.dll';
$phpConf['apache']['2.2']['AddModule'] = '';
?>

2. Wamp的安装目录/wampmanager.ini

复制代码
代码如下:

[phpVersion]
;WAMPPHPVERSIONSTART
Type: item; Caption: "5.2.17"; Action: multi; Actions:switchPhp5.2.17; Glyph: 13
Type: item; Caption: "5.3.0"; Action: multi; Actions:switchPhp5.3.0
Type: separator;
Type: item; Caption: "Get more..."; Action: run; FileName: "C:/Program Files (x86)/Mozilla Firefox/firefox.exe"; Parameters: "http://www.wampserver.com/addons_php.php";
[switchPhp5.2.17]
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "D:/programs/wamp/bin/php/php5.3.0/php-win.exe";Parameters: "switchPhpVersion.php 5.2.17";WorkingDir: "D:/programs/wamp/scripts"; Flags: waituntilterminated
Action: run; FileName: "D:/programs/wamp/bin/php/php5.3.0/php-win.exe";Parameters: "-c . refresh.php";WorkingDir: "D:/programs/wamp/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start wampapache"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;
[switchPhp5.3.0]
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: run; FileName: "D:/programs/wamp/bin/php/php5.3.0/php-win.exe";Parameters: "switchPhpVersion.php 5.3.0";WorkingDir: "D:/programs/wamp/scripts"; Flags: waituntilterminated
Action: run; FileName: "D:/programs/wamp/bin/php/php5.3.0/php-win.exe";Parameters: "-c . refresh.php";WorkingDir: "D:/programs/wamp/scripts"; Flags: waituntilterminated
Action: run; FileName: "net"; Parameters: "start wampapache"; ShowCmd: hidden; Flags: waituntilterminated
Action: resetservices
Action: readconfig;
;WAMPPHPVERSIONEND

如果要复制以上文件,注意更改版本号与路径。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表