PEAR is PHP’s equivalent of Perl’s CPAN. It offers hundreds of ready-to-use code modules that can make projects go much more quickly than having to hand code everything. However, it never seems like PEAR is easy to get running.
Installing the Needed Software
In Ubuntu, installing the following packages will quickly get you started with PEAR: php5-cli, php5-dev, and php-pear.
Make sure that you read the next section about problems with using PEAR to install PEAR packages if you are running 9.10, Karmic Kaola.
Here’s an example of how to quickly install those packages from the terminal.
[chris@rommie ~]$ sudo apt-get install php5-cli php5-dev php-pear Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: autoconf autoconf2.13 automake automake1.4 autotools-dev libltdl-dev libssl-dev libtool m4 php5-common shtool zlib1g-dev Suggested packages: autobook autoconf-archive gnu-standards autoconf-doc gettext libtool-doc automaken gfortran fortran95-compiler gcj php5-suhosin The following NEW packages will be installed: autoconf autoconf2.13 automake automake1.4 autotools-dev libltdl-dev libssl-dev libtool m4 php-pear php5-cli php5-common php5-dev shtool zlib1g-dev 0 upgraded, 15 newly installed, 0 to remove and 5 not upgraded. Need to get 0B/8,690kB of archives. After this operation, 27.7MB of additional disk space will be used. Do you want to continue [Y/n]? y Selecting previously deselected package m4. (Reading database ... 127272 files and directories currently installed.) Unpacking m4 (from .../archives/m4_1.4.13-2_i386.deb) ... ...
With these packages, you are ready to roll with PHP and PEAR in Ubuntu.
Problem with Ubuntu 9.10 Karmic Kaola
A great thing about PEAR is that you can quickly install packages with a simple command. For example, “sudo pear install PHP_Parser-0.2.1” will install the PHP_Parser package. However, this doesn’t work properly in Ubuntu 9.10, Karmic Kaola.
Output of the standard PEAR install command can be seen below:
[chris@rommie ~]$ sudo pear install PHP_Parser-0.2.1 downloading PHP_Parser-0.2.1.tgz ... Starting to download PHP_Parser-0.2.1.tgz (70,782 bytes) .................done: 70,782 bytes
While this doesn’t look wrong, it has actually failed. Rather than installing the package, it has simply downloaded the archive, encountered an unchecked error, and crashed. A successful installation has a message saying that the installation is successful.
This problem can be easily fixed by giving the install command the “-Z” option. For example:
[chris@rommie ~]$ sudo pear install -Z PHP_Parser-0.2.1 downloading PHP_Parser-0.2.1.tar ... Starting to download PHP_Parser-0.2.1.tar (Unknown size) .............................................................................done: 533,504 bytes install ok: channel://pear.php.net/PHP_Parser-0.2.1
Notice the “install ok: …” portion of the message. That’s what you should see at the end of a successful installation.
For more details on this bug, please check out Bug #451314 on the Ubuntu bug tracker.
Did I help you?