在 WampServer 上手工安裝 PHP 的多個版本的方法分享
2024-07-16 17:45:13
供稿:網友
對于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