什麼是PEARphp
來自百度百科:PEAR是PHP擴展與應用庫(the PHP Extension and Application Repository)的縮寫。它是一個PHP擴展及應用的一個代碼倉庫,簡單地說,PEAR之於PHP就像是CPAN(Comprehensive Perl Archive Network)之於Perl。ide
因而可知PEAR是PHP代碼的倉庫,在這裏能夠找到不少有用的代碼,避免咱們重複寫一些功能,可是PEAR代碼包並非直接經過HTTP網站下載的,咱們須要安裝PEAR。oop
如何獲取並安裝PEAR測試
建議:下面操做在Windows 7環境下完成,一樣適用於Windows XP/2003/Vista/2008系統,部分操做帶有嘗試性,爲了不彎路,建議先看完本文,而後再進行相關操做。網站
若是PHP目錄下沒有自帶PEAR,即找不到go-pear.php文件,那麼就須要咱們手動下載go-pear.php文件,點擊這裏下載並另存爲go-pear.php,這個文件放到php.exe所在的PHP安裝目錄下,我這裏安裝目錄是D:\php5(下文以此目錄爲準),那麼go-pear.php的位置應該是D:\php5\go-pear.php。ui
開始 – 運行,輸入cmd,啓動命令提示符,輸入如下命令,主要是切換到go-pear.php目錄下,而後執行這個PHP腳本文件:this
1 2 3 |
cd D:\php5 D: php go-pear.php |
遺憾的是可能因爲個人PHP版本太新,上述操做提示失敗,具體的信息以下:.net
Deprecated: Assigning the return value of new by reference is deprecated in D:\php5\go-pear.php on line 733code
Sorry! Your PHP version is too new (5.3.8) for this go-pear.htm
Instead use http://pear.php.net/go-pear.phar for a more stable and current version of go-pear, more suited to your PHP version.
Thank you for your coopertion and sorry for the inconvenience!
意思是要求咱們到http://pear.php.net/go-pear.phar下載go-pear.phar文件,而後取代go-pear.php再試。下載好go-pear.phar文件並放到D:\php5文件夾中,執行下面的命令:
1 2 3 |
cd D:\php5 D: php go-pear.phar |
這時出現:
1 2 |
Are you installing a system-wide PEAR or a local copy? (system|local) [system] : |
按回車默認system而後繼續。如下是默認的pear的臨時、數據、配置、測試、執行目錄的設置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Below is a suggested file layout for your new PEAR installation. To change individual locations, type the number in front of the directory. Type 'all' to change all of them or simply press Enter to accept these locations. 1. Installation base ($prefix) : D:\php5 2. Temporary directory for processing : D:\php5\tmp 3. Temporary directory for downloads : D:\php5\tmp 4. Binaries directory : D:\php5 5. PHP code directory ($php_dir) : D:\php5\pear 6. Documentation directory : D:\php5\docs 7. Data directory : D:\php5\data 8. User-modifiable configuration files directory : D:\php5\cfg 9. Public Web Files directory : D:\php5\www 10. Tests directory : D:\php5\tests 11. Name of configuration file : C:\Windows\pear.ini 12. Path to CLI php.exe : D:\php5 1-12, 'all' or Enter to continue: |
直接回車使用默認值而後繼續安裝。原本覺得萬事大吉的,但是恰恰在這裏出現了錯誤:
Warning: date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘UTC’ for ‘8.0/no DST’ instead in phar://D:/php5/go-pear.phar/PEAR/Registry.php on line 1012
PEAR_Config::writeConfigFile fopen(‘C:\Windows\pear.ini’,’w’) failed (fopen(C:\Windows\pear.ini): failed to open stream: Permission denied)
看樣子是沒有權限寫入C:\Windows\pear.ini,因爲我使用的是Windows 7系統,而後普通用戶打開的命令提示符,在這裏固然沒有權限寫入C:\Windows目錄了,看來要另闢蹊徑了。回到剛纔Are you installing a system-wide PEAR or a local copy?這段,爲何不選擇local copy呢?網上都是直接說默認回車選擇system的,不想改寫C:\Windows目錄,因而我從新執行php go-pear.phar,而且選擇local。
1 2 3 |
Are you installing a system-wide PEAR or a local copy? (system|local) [system] : local Please confirm local copy by typing 'yes' : yes |
好了,這下正常了:-)
1 |
Would you like to alter php.ini <D:\php5\php.ini>? [Y/n] : |
而後就是上面這句,只有選擇Y贊成修改php.ini。
1 2 3 4 5 6 |
php.ini <D:\php5\php.ini> include_path updated. Current include path : .;C:\php\pear Configured directory : D:\php5\pear Currently used php.ini (guess) : D:\php5\php.ini Press Enter to continue: |
接着出現上面這段,看來沒有什麼好改的,直接回車確認便可。
到這裏應該能看到Thanks for using go-pear!這句了,那麼恭喜你,PEAR總算是安裝成功了!
如何安裝PEAR Package包
接下來讓咱們去PEAR網站上看看有什麼須要的吧。PEAR每一個包都有安裝命令的提示,好比說MDB2這個包,上面已經提示使用pear install MDB2命令安裝了,假設目錄仍是D:\php5,那麼咱們利用下面的命令試試:
1 2 3 |
cd D:\php5 D: pear install MDB2 |
結果出現下面這個錯誤:
1 2 3 4 5 |
D:\php5>pear install MDB2 downloading MDB2-2.4.1.tgz ... Starting to download MDB2-2.4.1.tgz (119,790 bytes) ..........................done: 119,790 bytes ERROR: failed to mkdir C:\php\pear\docs\MDB2\docs\examples |
沒法建立目錄,看來又是權限問題,索性以管理員身份啓動cmd命令提示符,而後從新執行上面的命令。此次總算安裝成功了install ok!
好了,關於PEAR我就介紹到這兒了,更多的用法仍是參考PEAR網站吧。