Windows环境下尝试安装并配置PHP PEAR备忘

什么是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网站吧。

相关文章
相关标签/搜索