PHP PEAR Introduction

PHP PEAR is a PHP Extension and Application Repository. PEAR is somewhat similar to Perl's CPAN and Ruby's RubyGems. PEAR functions like a Package Manager for PHP code and a whole lot more.

Installation

Install the php-pear package using your favorite Ubuntu package manager.

See InstallingSoftware for different ways to install the php-pear package.

Using PEAR

This section discusses some of the common uses of PEAR. For more detailed instructions on using PEAR see the PEAR Manual

pear remote-list

pear install <package_name>

pear list

pear list-files <package_name>

pear uninstall <package_name>

pear upgrade PEAR

Example

In this example, we'll install the System_Folders package. System_Folders provides methods to get the locations of various system folders like home directory, desktop folder and "My documents".

command:
sudo pear install System_Folders

output:
  Did not download optional dependencies: pear/XML_Parser, pear/XML_Util, use --alldeps to download automatically
  pear/Config can optionally use package "pear/XML_Parser"
  pear/Config can optionally use package "pear/XML_Util"
  downloading System_Folders-1.0.0.tgz ...
  Starting to download System_Folders-1.0.0.tgz (8,364 bytes)
  .....done: 8,364 bytes
  downloading Config-1.10.11.tgz ...
  Starting to download Config-1.10.11.tgz (27,718 bytes)
  ...done: 27,718 bytes
  install ok: channel://pear.php.net/Config-1.10.11
  install ok: channel://pear.php.net/System_Folders-1.0.0

Notice PEAR mentions some optional packages to install.

command:
pear list 

output:
Package            Version   State
System_Folders     1.0.0     stable

Note: You'll probably have other PEAR packages in the list. Some are installed when you install PHP.

command:
pear list-files System_Folders

output:
Installed Files For System_Folders
==================================
Type Install Path
php  /usr/share/php/System/Folders/Cached.php
doc  /usr/share/php/docs/System_Folders/examples/cached.php
doc  /usr/share/php/docs/System_Folders/examples/example.php
php  /usr/share/php/System/Folders.php

Note: The path names may vary depending on your system.

<?php

require_once 'System/Folders.php';
$sf = new System_Folders();
$home = $sf->getHome();
echo "$home\n";

?>

php system_folders_test.php

Note: to execute the above command you'll need to have php-cli installed on your system.

command:
sudo pear uninstall System_Folders

output:
uninstall ok: channel://pear.php.net/System_Folders-1.0.0

NOTES

1) Some PHP PEAR modules are packaged for installation using Ubuntu package managers, but if the package you're looking for is missing from Ubuntu and you will have to manually install them by using PEAR. See above for instructions.

For example:

pear install Image_color
pear install Image_Text
pear install channel://pear.php.net/Image_Text-0.5.2beta2

2) If you are trying to use Image_graph you may get

Warning: imagettfbbox() [function.imagettfbbox]:
Could not find/open font in /mnt/sites/asmtennis.net/web/PEAR/Image/Canvas/GD.php

unless you have installed TrueType fonts and created a symbolic link to them

$ sudo -i
# cd /usr/share/php/Image/Canvas
# ln -s /usr/share/fonts/truetype/msttcorefonts/ Fonts
$

Note: This guide has been tested on Ubuntu 6.06 (Dapper), Ubuntu 7.10 (Gutsy).


CategorySoftware

PhpPear (last edited 2008-10-10 17:09:36 by cpe-69-207-215-155)