You want to install a PEAR package.
Download and install the package from the PEAR Channel server using Pryus:
1 |
% php pyrus.phar install pear/Package_Name |
You can also install from another PEAR Channel:
1 |
% php pyrus.phar install channel/Package_Name |
You can also install from any location on the Internet:
1 |
% php pyrus.phar install http://pear.example.com/Package_Name-1.0.0.tgz |
Here’s how to install if you have a local copy of a package:
1 |
% php pyrus.phar install Package_Name-1.0.0.tgz |
To install PEAR packages, you need write permission where the packages are stored; this defaults to /usr/local/lib/php/.
You can also request multiple packages at the same time:
1 2 3 4 5 6 7 8 9 10 |
% php pyrus.phar install pear/XML_RSS pear/XML_SVG Pyrus version 2.0.0a4 SHA-1: 72271D92C3AA1FA96DF9606CD538868544609A52 Using PEAR installation found at /Users/rasmus/lib Downloading pear.php.net/XML_RSS Mime-type: application/octet-stream Downloading pear.php.net/XML_SVG==============================>] 100% ( 6/ 6 kb) Mime-type: application/octet-stream Installed pear.php.net/XML_RSS-1.0.2==========================>] 100% ( 7/ 7 kb) Installed pear.php.net/XML_SVG-1.1.0 |
When installing a package, Pyrus checks that you have all the necessary PHP functions and PEAR packages that the new package depends on.
If this check fails, it installs all required PEAR dependencies:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
% php pyrus.phar install pear/XML_XUL-alpha Pyrus version 2.0.0a4 SHA-1: 72271D92C3AA1FA96DF9606CD538868544609A52 Using PEAR installation found at /Users/rasmus/lib Downloading pear.php.net/XML_XUL Mime-type: application/octet-stream Downloading pear.php.net/XML_Util2===========================>] 100% (26/26 kb) Mime-type: application/octet-stream Downloading pear.php.net/XML_Parser2=========================>] 100% (16/16 kb) Mime-type: application/octet-stream Installed pear.php.net/XML_XUL-0.9.1=========================>] 100% (11/11 kb) Installed pear.php.net/XML_Util2-0.1.0 Installed pear.php.net/XML_Parser2-0.1.0 |
Once a PEAR package is installed, use it in your PHP scripts by calling require_once.
For example, here’s how to include the HTTP_Request2 package:
1 |
require_once 'HTTP/Request2.php'; |
Generally, if a package name contains an underscore, replace it with a slash, and add .php to the end.
Because PEAR packages are included as regular PHP files, make sure the directory containing the PEAR packages is in your include_path.
If it isn’t, include_once and require_once can’t find PEAR class files.