PHP pear安装配置教程,pear安装配置教程
什么是PEAR?
PEAR是PHP扩展与应用库(the PHP Extension and Application Repository)的缩写。它是一个PHP扩展及应用的一个代码仓库,简单地说,PEAR之于PHP就像是CPAN(Comprehensive Perl Archive Network)之于Perl。
由此可见PEAR是PHP代码的仓库,在这里可以找到很多有用的代码,避免我们重复写一些功能,但是PEAR代码包并不是直接通过HTTP网站下载的,我们需要安装PEAR。
如何获取并安装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。
开始 – 运行,输入cmd,启动命令提示符,输入以下命令,主要是切换到go-pear.php目录下,然后执行这个PHP脚本文件:
cd D:\php5
D:
php go-pear.php
遗憾的是可能由于我的PHP版本太新,上述操作提示失败,具体的信息如下:
Deprecated: Assigning the return value of new by reference is deprecated in D:\php5\go-pear.php on line 733
Sorry! Your PHP version is too new (5.3.8) for this go-pear.
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文件夹中,执行下面的命令:
cd D:\php5
D:
php go-pear.phar
这时出现:
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :
按回车默认system然后继续。以下是默认的pear的临时、数据、配置、测试、执行目录的设置:
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。
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] : local
Please confirm local copy by typing 'yes' : yes
好了,这下正常了:-)
Would you like to alter php.ini
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,那么我们利用下面的命令试试:
cd D:\php5
D:
pear install MDB2
结果出现下面这个错误:
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!
另一个安装报错案例:PHP pear安装出现 Warning: require_once(Structures/Graph.php)...错误
在WINDOWS安装pear,一路无阻很顺利安装完成,接着想安装下pear email包来玩下,但接下来却报:
Warning: require_once(Structures/Graph.php): failed to open stream: No such file
or directory in PEAR\Downloader.php on line 1217
PHP Warning: require_once(Structures/Graph.php): failed to open stream: No such
file or directory in E:\Program Files\php5_3\pear\pear\PEAR\Downloader.php on l
ine 1217
新手没办法,网上找解决。折腾了老半天,还是报这错误.原因很清楚就是少了Structures_Graph这个PEAR应用,相直接通用pear命令:
pear install Structures_Graph-1.1.1
在线安装这个应用,但让人痛心的是竟然也报同样的错误,我丢。。
不跟它玩了直接到PEAR官网下载Structures_Graph-1.1.0.tgz包。解压看看里面的结构;发现里面正好有一个Structures/Graph.php;于是解压并把压缩包里的Structures文件夹放到pear根目下面。接着再运行Structures_Graph的安装命令,惊喜!!成功了。
接着再安装email,不出意外也成功。到此这个纠结了我半天的问题终于解决了。
谢谢大家的阅读哦!

PHP用於構建動態網站,其核心功能包括:1.生成動態內容,通過與數據庫對接實時生成網頁;2.處理用戶交互和表單提交,驗證輸入並響應操作;3.管理會話和用戶認證,提供個性化體驗;4.優化性能和遵循最佳實踐,提升網站效率和安全性。

PHP在數據庫操作和服務器端邏輯處理中使用MySQLi和PDO擴展進行數據庫交互,並通過會話管理等功能處理服務器端邏輯。 1)使用MySQLi或PDO連接數據庫,執行SQL查詢。 2)通過會話管理等功能處理HTTP請求和用戶狀態。 3)使用事務確保數據庫操作的原子性。 4)防止SQL注入,使用異常處理和關閉連接來調試。 5)通過索引和緩存優化性能,編寫可讀性高的代碼並進行錯誤處理。

在PHP中使用預處理語句和PDO可以有效防範SQL注入攻擊。 1)使用PDO連接數據庫並設置錯誤模式。 2)通過prepare方法創建預處理語句,使用佔位符和execute方法傳遞數據。 3)處理查詢結果並確保代碼的安全性和性能。

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP可以輕鬆創建互動網頁內容。 1)通過嵌入HTML動態生成內容,根據用戶輸入或數據庫數據實時展示。 2)處理表單提交並生成動態輸出,確保使用htmlspecialchars防XSS。 3)結合MySQL創建用戶註冊系統,使用password_hash和預處理語句增強安全性。掌握這些技巧將提升Web開發效率。

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

記事本++7.3.1
好用且免費的程式碼編輯器

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版
好用的JavaScript開發工具