PEAR (short for PHP Extension and Application Repository) is a framework and distribution system for reusable PHP components. In includes many useful tools and components that can be easily downloaded and installed by using PEAR package manager. This post describes how to install and configure PEAR package manager and then how to use it to install a PEAR package. An example PEAR package used in this post is phploc, which is a tool for measuring the size of PHP projects.
Start by installing PHP on Windows by using one of the following methods:
- Install PHP for by using Web PI 3.0. With that you can install PHP for either IIS or WebMatrix or both;
- Download and unpack the PHP zip package and then register it with IIS by using PHP Manager.
Now open an elevated command line prompt and go to the directory where PHP was installed. For example if PHP 5.3 was installed with Web PI 3.0 then the directory path will be:
- %ProgramFiles%\PHP\v53\ – when PHP is installed for IIS
- %ProgramFiles%\IIS Express\PHP\v53 – when PHP is installed for IIS Express
While in that directory run the go-pear.bat command. If you intend on having multiple versions of PHP installed on the same machine then make sure to answer “local” on the first question asked by go-pear.bat:
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] : local
Please confirm local copy by typing 'yes' : yes
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) : C:\Program Files\PHP\v5.3
2. Temporary directory for processing : C:\Program Files\PHP\v5.3\tmp
3. Temporary directory for downloads : C:\Program Files\PHP\v5.3\tmp
4. Binaries directory : C:\Program Files\PHP\v5.3
5. PHP code directory ($php_dir) : C:\Program Files\PHP\v5.3\pear
6. Documentation directory : C:\Program Files\PHP\v5.3\docs
7. Data directory : C:\Program Files\PHP\v5.3\data
8. User-modifiable configuration files directory : C:\Program Files\PHP\v5.3\cfg
9. Public Web Files directory : C:\Program Files\PHP\v5.3\www
10. Tests directory : C:\Program Files\PHP\v5.3\tests
11. Name of configuration file : C:\Program Files\PHP\v5.3\pear.ini
12. Path to CLI php.exe : .
1-12, 'all' or Enter to continue:
Continue following the prompts to complete the installation process. During the installation you may see a warning similar to the one shown below:
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 <C:\Program Files\PHP\v5.3\php.ini>? [Y/n] : y
Make sure to say yes [y] to the question about altering php.ini so that include_path directive is updated to the correct PEAR PHP directorty
After that you may also get a warning about out-of-date version of PEAR package manager:
** WARNING! Old version found at C:\Program Files\PHP\v5.3, please remove it or
be sure to use the new c:\program files\php\v5.3\pear.bat command
If you see that then after the go-pear.bat has finished its work, run the following command to upgrade the PEAR package manager:
C:\Program Files\PHP\v5.3>pear upgrade pear
downloading PEAR-1.9.1.tgz ...
Starting to download PEAR-1.9.1.tgz (293,587 bytes)
.................done: 293,587 bytes
downloading Archive_Tar-1.3.7.tgz ...
Starting to download Archive_Tar-1.3.7.tgz (17,610 bytes)
...done: 17,610 bytes
downloading Structures_Graph-1.0.4.tgz ...
Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes)
...done: 30,318 bytes
upgrade ok: channel://pear.php.net/Archive_Tar-1.3.7
upgrade ok: channel://pear.php.net/Structures_Graph-1.0.4
upgrade ok: channel://pear.php.net/PEAR-1.9.1
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"
At this point PEAR package manager is installed and you can start using it to download and install PEAR packages. For example to install phploc package, follow these steps:
Step 1: Register the appropriate PEAR channels:
C:\Program Files\PHP\v5.3>pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded
C:\Program Files\PHP\v5.3>pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded
Step 2: Install the phploc package:
C:\Program Files\PHP\v5.3>pear install phpunit/phploc
phpunit/phploc can optionally use PHP extension "bytekit"
downloading phploc-1.5.1.tgz ...
Starting to download phploc-1.5.1.tgz (7,893 bytes)
.....done: 7,893 bytes
downloading File_Iterator-1.2.3.tgz ...
Starting to download File_Iterator-1.2.3.tgz (3,406 bytes)
...done: 3,406 bytes
downloading ConsoleTools-1.6.1.tgz ...
Starting to download ConsoleTools-1.6.1.tgz (869,994 bytes)
...done: 869,994 bytes
downloading Base-1.8.tgz ...
Starting to download Base-1.8.tgz (236,357 bytes)
...done: 236,357 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.2.3
install ok: channel://components.ez.no/Base-1.8
install ok: channel://components.ez.no/ConsoleTools-1.6.1
install ok: channel://pear.phpunit.de/phploc-1.5.1
Finally run the phploc to ensure that it works correctly:
phploc 1.5.1 by Sebastian Bergmann.
Usage: phploc [switches] <directory|file> ...
--count-tests Count PHPUnit test case classes and test methods.
--log-xml <file> Write result in XML format to file.
--exclude <directory> Exclude <directory> from code analysis.
--suffixes <suffix,...> A comma-separated list of file suffixes to check.
--help Prints this usage information.
--version Prints the version and exits.
--verbose Print progress bar.
Read the complete post here