How to install PHP PEAR and phploc on Windows

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:

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:

C:\Program Files\PHP\v5.3>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:
<C:\Program Files\PHP\v5.3\pear>
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://
upgrade ok: channel://
upgrade ok: channel://
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
Adding Channel "" succeeded
Discovery of channel "" succeeded

C:\Program Files\PHP\v5.3>pear channel-discover
Adding Channel "" succeeded
Discovery of channel "" 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://
install ok: channel://
install ok: channel://
install ok: channel://

Finally run the phploc to ensure that it works correctly:

C:\Program Files\PHP\v5.3>phploc
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.


ruslany on November 22nd 2010 in PHP

PoorFairAverageGoodExcellent (2 votes, average: 4.50 out of 5)

4 Responses to “How to install PHP PEAR and phploc on Windows”

  1. Gravatar ImageRob... responded on 22 Nov 2010 at 11:51 am #


    You should probably advise which PHP zip package to install :)

    I believe that it’s the VC9, non-threadsafe, but there’s a lot of choice at


  2. Gravatar Imageruslany responded on 22 Nov 2010 at 11:53 am #

    Good point. Updated the post. Thanks for the feedback!

  3. Gravatar Imagechris responded on 25 Nov 2010 at 11:01 am #

    PEAR is dead… too many unmaintained projects and changing API’s it’s a nightmare for maintenance in the long run ;)

  4. Gravatar ImageMasood Aslami responded on 28 Nov 2010 at 9:34 am #

    Thanks a lot RuslanY…. it was very helpful to me.

Trackback URI | Comments RSS

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

XML Markup: If You want to add XML code to the comment please XML encode it first, otherwise the code will not show up.

Recently Published Articles