不常用的基础 - 安装Pear

  • 作者:KK

  • 发表日期:2016.8.19


pear的介绍

Pear是一个PHP代码仓库,安装后可以在线下载别人写好的代码来用,这个时代我们程序员要写的代码其实已经少了好多,大部分是下载别人的代码来组装调用实现各种功能,这些代码还能被各个不同的项目重用,就不用每个项目都部署一份相同的代码了

怎么知道有没有安装pear

看看PHP目录下有没有pear目录,没有就是没安装咯

安装pear

点击下载官方的go-pear.phar,这是个PHP文件,下载后放到PHP目录下

启动命令行,cd到php目录下执行php go-pear.phar会输出:

D:\phpStudy\php70n>php go-pear.phar

Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :

这里是问你安装的pear是当前的系统用户使用还是整台电脑的其他用户都能用?

一般就自己用,难道妈妈姐姐登陆的系统账号都会用pear跟你写PHP代码吗?你想想咯

给自己用的话就输入local回车,接下来是:

Please confirm local copy by typing 'yes' :

确认一下是不是这样安装(为自己安装),输入yes回车,到:

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:\phpStudy\php70n
 2. Temporary directory for processing            : D:\phpStudy\php70n\tmp
 3. Temporary directory for downloads             : D:\phpStudy\php70n\tmp
 4. Binaries directory                            : D:\phpStudy\php70n
 5. PHP code directory ($php_dir)                 : D:\phpStudy\php70n\pear
 6. Documentation directory                       : D:\phpStudy\php70n\docs
 7. Data directory                                : D:\phpStudy\php70n\data
 8. User-modifiable configuration files directory : D:\phpStudy\php70n\cfg
 9. Public Web Files directory                    : D:\phpStudy\php70n\www
10. System manual pages directory                 : D:\phpStudy\php70n\man
11. Tests directory                               : D:\phpStudy\php70n\tests
12. Name of configuration file                    : D:\phpStudy\php70n\pear.ini
13. Path to CLI php.exe                           : D:\phpStudy\php70n

1-13, 'all' or Enter to continue:

这个刚接触的话你可以直接回车

  • 解读

    上面那堆选项提示,意思是安装pear会涉及到13个目录参数,这些目录分别是pear的配置目录呀,运行时的临时目录,下载时的临时目录,单元测试代码目录,文档目录。。。等

    并且在每个项目的右边列出了默认的路径,问你要不要修改,如果要修改就输入对应的项目数字并修改,如果不改就直接回车


接下来安装过程中一般都会提示

WARNING!  The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<D:\phpStudy\php70n\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.


Would you like to alter php.ini <D:\phpStudy\php70n\php.ini>? [Y/n] :

刚接触的话直接输入Y并回车确认吧

  • 解读

    这其实是说php.ini配置的include_path不包含D:\phpStudy\php70n\pear这个路径,输入Y就自动给你添加到php.ini里,不然跑不起pear的

哎呀它又来烦人了,问:

php.ini <D:\phpStudy\php70n\php.ini> include_path updated.

Current include path           : .;C:\php\pear
Configured directory           : D:\phpStudy\php70n\pear
Currently used php.ini (guess) : D:\phpStudy\php70n\php.ini
Press Enter to continue:

你就回车吧,它只是确认要不要这样更新include_path,一般都要的了


基本可以了,最后安装完成之前它可能会提示:

** WARNING! Old version found at D:\phpStudy\php70n, please remove it or be sure to use the new d:\projects\backup\server\php70n\pear.bat command

The 'pear' command is now at your service at d:\phpStudy\php70n\pear.bat

这是说你已经有了旧版本的pear,其实新手安装一般不会遇到这个提示,我就补一下


验证是否安装成功

就在PHP目录下运行pear -V如果有版本信息输出那么就是安装成功了


如果还安装不正常那可以上网找找其他安装教程,有更多讲解遇到安装报错时如何解决,比如推荐这篇:

http://www.cnblogs.com/bugY/archive/2012/07/06/2578972.html