静思学吧 - 关注Graphite,Puppet,saltstack, Zabbix
PHP 的 pear 相当于 Perl 的 cpan 、Python 的 pip 和 Ruby 的 gem, 是用来管理扩展包的一个工具。 本文简单讲解一下 PHP pear 工具的安装和使用。
虽然是个巨大的鸭梨( pear 有梨的含义),但是在安装和使用 pear 的过程中毫无压力,非常容易上手和使用。
一、 pear 安装
pear 的安装很简单, 且每个平台的安装方法都统一。
首先下载这个文件: go-pear.phar , 然后使用 php 命令来执行这个文件, Linux上的命令如下:
$ wget http://pear.php.net/go-pear.phar $ php go-pear.phar
这样就安装完成了。
以上安装方法参考 Getting and installing the PEAR package manager , 如果安装过程遇到任何错误亦可查看这个页面排除问题。
二、 pear 使用
例如安装 Text_CAPTCHA 这个扩展可以使用以下命令:
pear install --alldeps channel://pear.php.net/Text_CAPTCHA-0.4.3
其中参数和选项说明如下:
- install 表示安装扩展包
- –alldeps 表示自动安装依赖包, 默认不安装
- channel://pear.php.net/Text_CAPTCHA-0.4.3 表示扩展, 因为 Text_CAPTCHA 是 beta 版本, 因此不能直接使用扩展名进行安装。
其它的命令与一般的包管理软件类似。
下面将 pear 的所有命令和选项贴出来, 以使得您不用再查阅其它资料。
三、 pear 命令汇总
执行 pear help 可以查看。 如果需要查看某个命令( command )的使用参数的方法可以执行 pear help command 进行查看。
Commands: build Build an Extension From C Source bundle Unpacks a Pecl Package channel-add Add a Channel channel-alias Specify an alias to a channel name channel-delete Remove a Channel From the List channel-discover Initialize a Channel from its server channel-info Retrieve Information on a Channel channel-login Connects and authenticates to remote channel server channel-logout Logs out from the remote channel server channel-update Update an Existing Channel clear-cache Clear Web Services Cache config-create Create a Default configuration file config-get Show One Setting config-help Show Information About Setting config-set Change Setting config-show Show All Settings convert Convert a package.xml 1.0 to package.xml 2.0 format cvsdiff Run a "cvs diff" for all files in a package cvstag Set CVS Release Tag download Download Package download-all Downloads each available package from the default channel info Display information about a package install Install Package list List Installed Packages In The Default Channel list-all List All Packages list-channels List Available Channels list-files List Files In Installed Package list-upgrades List Available Upgrades login Connects and authenticates to remote server [Deprecated in favor of channel-login] logout Logs out from the remote server [Deprecated in favor of channel-logout] makerpm Builds an RPM spec file from a PEAR package package Build Package package-dependencies Show package dependencies package-validate Validate Package Consistency pickle Build PECL Package remote-info Information About Remote Packages remote-list List Remote Packages run-scripts Run Post-Install Scripts bundled with a package run-tests Run Regression Tests search Search remote package database shell-test Shell Script Test sign Sign a package distribution file svntag Set SVN Release Tag uninstall Un-install Package update-channels Update the Channel List upgrade Upgrade Package upgrade-all Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters] Usage: pear [options] command [command-options] <parameters> Type "pear help options" to list all options. Type "pear help shortcuts" to list all command shortcuts. Type "pear help <command>" to get the help for the specified command.
四、 pear 选项
执行 pear help options 可以查看。如果需要查看某个命令( command )的使用参数的方法可以执行 pear help command 进行查看。
Options: -v increase verbosity level (default 1) -q be quiet, decrease verbosity level -c file find user configuration in `file' -C file find system configuration in `file' -d foo=bar set user config variable `foo' to `bar' -D foo=bar set system config variable `foo' to `bar' -G start in graphical (Gtk) mode -s store user configuration -S store system configuration -u foo unset `foo' in the user configuration -h, -? display help/usage (this message) -V version information
五、 pear 快捷命令
执行 pear help shortcuts 可以查看。
Shortcuts: b build bun bundle c2 convert ca channel-add cc clear-cache cd cvsdiff cde channel-delete cg config-get ch config-help cha channel-alias ci channel-info cli channel-login clo channel-logout coc config-create cs config-set csh config-show ct cvstag cu channel-update d download da download-all di channel-discover fl list-files i install in info l list la list-all lc list-channels li login lo logout lu list-upgrades p package pd package-dependencies pi pickle pv package-validate ri remote-info rl remote-list rpm makerpm rs run-scripts rt run-tests si sign sp search st shell-test sv svntag ua upgrade-all uc update-channels un uninstall up upgrade