PHP pear安装配置教程
什么是PEAR?
PEAR是PHP扩展与应用库(thePHPExtensionandApplicationRepository)的缩写。它是一个PHP扩展及应用的一个代码仓库,简单地说,PEAR之于PHP就像是CPAN(ComprehensivePerlArchiveNetwork)之于Perl。
由此可见PEAR是PHP代码的仓库,在这里可以找到很多有用的代码,避免我们重复写一些功能,但是PEAR代码包并不是直接通过HTTP网站下载的,我们需要安装PEAR。
如何获取并安装PEAR
建议:下面操作在Windows7环境下完成,同样适用于WindowsXP/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脚本文件:
cdD:\php5
D:
phpgo-pear.php
遗憾的是可能由于我的PHP版本太新,上述操作提示失败,具体的信息如下:
Deprecated:AssigningthereturnvalueofnewbyreferenceisdeprecatedinD:\php5\go-pear.phponline733
Sorry!YourPHPversionistoonew(5.3.8)forthisgo-pear.
Insteadusehttp://pear.php.net/go-pear.pharforamorestableandcurrentversionofgo-pear,moresuitedtoyourPHPversion.
Thankyouforyourcoopertionandsorryfortheinconvenience!
意思是要求我们到http://pear.php.net/go-pear.phar下载go-pear.phar文件,然后取代go-pear.php再试。下载好go-pear.phar文件并放到D:\php5文件夹中,执行下面的命令:
cdD:\php5
D:
phpgo-pear.phar
这时出现:
Areyouinstallingasystem-widePEARoralocalcopy?
(system|local)[system]:
按回车默认system然后继续。以下是默认的pear的临时、数据、配置、测试、执行目录的设置:
BelowisasuggestedfilelayoutforyournewPEARinstallation.To changeindividuallocations,typethenumberinfrontofthe directory.Type'all'tochangeallofthemorsimplypressEnterto accepttheselocations. 1.Installationbase($prefix):D:\php5 2.Temporarydirectoryforprocessing:D:\php5\tmp 3.Temporarydirectoryfordownloads:D:\php5\tmp 4.Binariesdirectory:D:\php5 5.PHPcodedirectory($php_dir):D:\php5\pear 6.Documentationdirectory:D:\php5\docs 7.Datadirectory:D:\php5\data 8.User-modifiableconfigurationfilesdirectory:D:\php5\cfg 9.PublicWebFilesdirectory:D:\php5\www 10.Testsdirectory:D:\php5\tests 11.Nameofconfigurationfile:C:\Windows\pear.ini 12.PathtoCLIphp.exe:D:\php5 1-12,'all'orEntertocontinue:
直接回车使用默认值然后继续安装。本来以为万事大吉的,可是偏偏在这里出现了错误:
Warning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected‘UTC'for'8.0/noDST'insteadinphar://D:/php5/go-pear.phar/PEAR/Registry.phponline1012
PEAR_Config::writeConfigFilefopen(‘C:\Windows\pear.ini','w')failed(fopen(C:\Windows\pear.ini):failedtoopenstream:Permissiondenied)
看样子是没有权限写入C:\Windows\pear.ini,由于我使用的是Windows7系统,然后普通用户打开的命令提示符,在这里当然没有权限写入C:\Windows目录了,看来要另辟蹊径了。回到刚才Areyouinstallingasystem-widePEARoralocalcopy?这段,为什么不选择localcopy呢?网上都是直接说默认回车选择system的,不想改写C:\Windows目录,于是我重新执行phpgo-pear.phar,并且选择local。
Areyouinstallingasystem-widePEARoralocalcopy?
(system|local)[system]:local
Pleaseconfirmlocalcopybytyping'yes':yes
好了,这下正常了:-)
Wouldyouliketoalterphp.ini<D:\php5\php.ini>?[Y/n]:
然后就是上面这句,只有选择Y同意修改php.ini。
php.ini<D:\php5\php.ini>include_pathupdated. Currentincludepath:.;C:\php\pear Configureddirectory:D:\php5\pear Currentlyusedphp.ini(guess):D:\php5\php.ini PressEntertocontinue:
接着出现上面这段,看来没有什么好改的,直接回车确认即可。
到这里应该能看到Thanksforusinggo-pear!这句了,那么恭喜你,PEAR总算是安装成功了!
如何安装PEARPackage包
接下来让我们去PEAR网站上看看有什么需要的吧。PEAR每个包都有安装命令的提示,比如说MDB2这个包,上面已经提示使用pearinstallMDB2命令安装了,假设目录还是D:\php5,那么我们利用下面的命令试试:
cdD:\php5
D:
pearinstallMDB2
结果出现下面这个错误:
D:\php5>pearinstallMDB2 downloadingMDB2-2.4.1.tgz... StartingtodownloadMDB2-2.4.1.tgz(119,790bytes) ..........................done:119,790bytes ERROR:failedtomkdirC:\php\pear\docs\MDB2\docs\examples
无法创建目录,看来又是权限问题,索性以管理员身份启动cmd命令提示符,然后重新执行上面的命令。这次总算安装成功了installok!
另一个安装报错案例:PHPpear安装出现Warning:require_once(Structures/Graph.php)...错误
在WINDOWS安装pear,一路无阻很顺利安装完成,接着想安装下pearemail包来玩下,但接下来却报:
Warning:require_once(Structures/Graph.php):failedtoopenstream:Nosuchfile
ordirectoryinPEAR\Downloader.phponline1217
PHPWarning: require_once(Structures/Graph.php):failedtoopenstream:Nosuch
fileordirectoryinE:\ProgramFiles\php5_3\pear\pear\PEAR\Downloader.phponl
ine1217
新手没办法,网上找解决。折腾了老半天,还是报这错误.原因很清楚就是少了Structures_Graph这个PEAR应用,相直接通用pear命令:
pearinstallStructures_Graph-1.1.1
在线安装这个应用,但让人痛心的是竟然也报同样的错误,我丢。。
不跟它玩了直接到PEAR官网下载Structures_Graph-1.1.0.tgz包。解压看看里面的结构;发现里面正好有一个Structures/Graph.php;于是解压并把压缩包里的Structures文件夹放到pear根目下面。接着再运行Structures_Graph的安装命令,惊喜!!成功了。
接着再安装email,不出意外也成功。到此这个纠结了我半天的问题终于解决了。
谢谢大家的阅读哦!