php5.3 pear,php-5.3 下安装pear 和 pecl

环境描述:服务器php安装好之后,bin目录下没有pecl、pear等命令,从而导致安装memcache、apc等php扩展比较麻烦。

一、安装pear、pecl

1、下载go-pear

[root@yf_web_115 bin]# curl -o go-pear.php http://pear.php.net/go-pear.phar

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

Dload  Upload   Total   Spent    Left  Speed

100 3987k  100 3987k    0     0  30213      0  0:02:15  0:02:15 –:–:–  117k

2、php 执行go-pear

[root@yf_web_115 bin]# /opt/phpdba/php-5.3.27/bin/php go-pear.php

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)                   : /opt/phpdba/php-5.3.27

2. Temporary directory for processing            : /tmp/pear/install

3. Temporary directory for downloads             : /tmp/pear/install

4. Binaries directory                            : /opt/phpdba/php-5.3.27/bin

5. PHP code directory ($php_dir)                 : /opt/phpdba/php-5.3.27/share/pear

6. Documentation directory                       : /opt/phpdba/php-5.3.27/docs

7. Data directory                                : /opt/phpdba/php-5.3.27/data

8. User-modifiable configuration files directory : /opt/phpdba/php-5.3.27/cfg

9. Public Web Files directory                    : /opt/phpdba/php-5.3.27/www

10. Tests directory                               : /opt/phpdba/php-5.3.27/tests

11. Name of configuration file                    : /opt/phpdba/php-5.3.27/etc/pear.conf

1-11, ‘all’ or Enter to continue:

Beginning install…

Configuration written to /opt/phpdba/php-5.3.27/etc/pear.conf…

Initialized registry…

Preparing to install…

installing phar:///opt/phpdba/php-5.3.27/bin/go-pear.php/PEAR/go-pear-tarballs/Archive_Tar-1.3.11.tar…

installing phar:///opt/phpdba/php-5.3.27/bin/go-pear.php/PEAR/go-pear-tarballs/Console_Getopt-1.3.1.tar…

installing phar:///opt/phpdba/php-5.3.27/bin/go-pear.php/PEAR/go-pear-tarballs/PEAR-1.9.4.tar…

installing phar:///opt/phpdba/php-5.3.27/bin/go-pear.php/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar…

installing phar:///opt/phpdba/php-5.3.27/bin/go-pear.php/PEAR/go-pear-tarballs/XML_Util-1.2.1.tar…

install ok: channel://pear.php.net/Archive_Tar-1.3.11

install ok: channel://pear.php.net/Console_Getopt-1.3.1

install ok: channel://pear.php.net/Structures_Graph-1.0.4

install ok: channel://pear.php.net/XML_Util-1.2.1

install ok: channel://pear.php.net/PEAR-1.9.4

PEAR: Optional feature webinstaller available (PEAR’s web-based installer)

PEAR: Optional feature gtkinstaller available (PEAR’s PHP-GTK-based installer)

PEAR: Optional feature gtk2installer available (PEAR’s PHP-GTK2-based installer)

PEAR: To install optional features use “pear install pear/PEAR#featurename”

******************************************************************************

WARNING!  The include_path defined in the currently used php.ini does not

contain the PEAR PHP directory you just specified:

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 ? [Y/n] : Y

php.ini include_path updated.

Current include path           : .:

Configured directory           : /opt/phpdba/php-5.3.27/share/pear

Currently used php.ini (guess) : /opt/phpdba/php-5.3.27/etc/php.ini

Press Enter to continue:

** WARNING! Old version found at /opt/phpdba/php-5.3.27/bin, please remove it or be sure to use the new /opt/phpdba/php-5.3.27/bin/pear command

The ‘pear’ command is now at your service at /opt/phpdba/php-5.3.27/bin/pear

** The ‘pear’ command is not currently in your PATH, so you need to

** use ‘/opt/phpdba/php-5.3.27/bin/pear’ until you have added

** ‘/opt/phpdba/php-5.3.27/bin’ to your PATH environment variable.

Run it without parameters to see the available actions, try ‘pear list’

to see what packages are installed, or ‘pear help’ for help.

For more information about PEAR, see:

http://pear.php.net/faq.php

http://pear.php.net/manual/

Thanks for using go-pear!

3、检查php/bin目录下pear pecl

[root@yf_web_115 bin]# ls

go-pear.php  pear  peardev  pecl  phar  phar.phar  php  php-config  phpize

二、安装过程中遇到的问题

[root@yf_web_115 bin]# curl -o go-pear.php http://pear.php.net/go-pear

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

Dload  Upload   Total   Spent    Left  Speed

100 88959  100 88959    0     0  54233      0  0:00:01  0:00:01 –:–:– 76033

[root@yf_web_115 bin]# /opt/phpdba/php-5.3.27/bin/php go-pear.php

Sorry!  Your PHP version is too new (5.3.27) 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

原因:go-pear.php 版本比较旧,下载新版本go-pear.php就可以解决问题。

三、知识详解

PECL

即PHP Extension Community Library, PHP扩展库.

这里的扩展指的是使用C语言编写的动态链接库扩展, 通过php.ini配置, 并随PHP进程被装入内存.

常见的PECL扩展比如:

apc – 字节码缓存器

xdebug – 调试工具

PDO_xxoo – 数据库驱动

memcache, mongo – NoSQL数据库驱动

markdown – 文本处理器

zip – 压缩算法

这种动态链接库又分两种, 一种是用户空间扩展, 如mongo, markdown, 旨在通过C代码提升性能, 为PHP代码提供更好的抽象.

另一种是Zend扩展, 这是对Zend内核(PHP引擎内核)的扩展, 如apc, xdebug.

PECL在Windows上并不好用, 通常的做法是直接下载形式如php_xxoo.dll的已编译好的二进制动态链接库.

下载时还应该选择对应PHP版本号, 处理器指令集, 线程安全性的版本.

据说PECL的基础设施还在建设中, 目前有个简陋的网页(http://downloads.php.net/pierre/)可以下载到一部分编译好的Windows PECL扩展.

而在Linux则方便不少, 比如要安装apc, 只需:

pecl install apc

即可, pecl是PHCL的命令行工具, 可以自动完成扩展的安装(通常是下载源代码后自动编译)工作.

PEAR

即PHP Extension and Application Repository, PHP扩展和应用库.

这里的扩展和应用, 指的是用PHP编写的软件包, 一系列类库性质的PEAR包会被安装到PHP的根目录, 然后你就可以在你的代码中直接包含(require)这些类库.

常见的PEAR包如:

phpDocumentor – 文档提取工具

PHPUnit – 单元测试框架

DB – 数据库封装

PEAR希望创建一个规范化的PHP源代码包仓库, PEAR本身也对源代码的格式提出了一些要求, 以便于让源码包更加通用和规范.

同时PEAR也是PECL的上级项目, PECL是PEAR的一部分, pecl的命令行工具也包含在PEAR中.

#安装标配的源码包:

pear install db

#PEAR也采用了`软件源`的设计, 安装非标配的软件包如phpunit, 需要先添加频道(软件源)

pear channel-discover pear.phpunit.de

pear install phpunit

PHAR

PHAR即PHP Archive, 起初只是PEAR中的一个库而已, 后来在PHP5.3后被重新编写成C扩展并内置到PHP中.

PEAR用来将多个.php脚本打包(也可以打包其他文件)成一个.phar的压缩文件(通常是ZIP格式).

目的在于模仿Java的.jar, 不对, 目的是为了让发布PHP应用程序更加方便. 同时还提供了数字签名验证等功能.

.phar文件可以像.php文件一样, 被PHP引擎解释执行, 同时你还可以写出这样的代码来包含(require) .phar 中的代码.

require("xxoo.phar");

require("phar://xxoo.phar/xo/ox.php");

PEAR中的很多源码包都通过PHAR打包.

bcompiler

提到了PHAR, 我还不得不提一下bcompiler, PHP bytecode Compiler, PHP字节码编译器.

虽然它目前只是个实验性项目. 可以通过pecl安装.

很多PHP编写的商业软件, 有闭源的需要, 通常它们会选择Zend Guard等商业代码加密软件, 它们成熟稳定, 但也价格昂贵.

其实bcompiler就能满足这个需求, 它可以将PHP代码编译成字节码, 虽然保密性不及商业加密软件, 但也很难被轻易修改, 而且因为省去了生成字节码的过程, 会有不少的性能提升, 官方表示编译后体积会减少到原来的20%, 性能会提高30%.

使用bcompiler编译出的PHP字节码文件可以直接使用(就像PEAR那样):

// xxoo.exe 是 xxoo.php 编译后的字节码.

require("xxoo.exe");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值