Installing latest PEAR and PHPUnit on Windows 7

pear and phpunit

pear and phpunitFor my recent project based on YII framework, I have to use PHPUnit for doing unit test.  My Local development environment is Windows 7 64 bit system. I have installed php 5.3.10, Apache 2.4 and MySQL 5.

Problem for me start from beginning when I looked for go-pear.bat file on my c:\\php directory to install pear. I was unable to locate go-pear.bat file in my php installation directory.

On it is clearly written to use this file to install pear itself. I googled a lot and found some of the useful instruction for pear installation, but unfortunately they either failed or too old to handle the new environment. After a day of long search I finally manage to install pear and PHPunit on my system.  If you also unable to find go-pear.php on your local php installation directory then you can take the following approach.

Here are the steps i have taken to solve this problem, this might also help you.

1.    In your php.ini file find the following line.
;phar.require_hash = On

2.    Remove the semi-colon from beginning of this line and change “On” to “Off” (without double quotes).

3.    Restart your apache server.

4.    Input this url in your browser, you will be prompted to download go-pear.phar file.

5.    Download go-pear.phar file and move it to the php installation directory (c:\\php in my case).

6.    Open cmd navigate to c:\\php and run the following command
php go-pear.phar

7.    Enter ‘local’ to the question asked. Follow the instruction.

8.    Restart apache.

PEAR has been installed successfully (no need to configure your environment variable). To check it, type pear on your cmd you will be able to see the help menu for the pear.

Now let’s install PHPUnit (I have installed PHPUnit 3.6.11). While installing PHPUnit when I run the below command (in point 9) I got the error “PEAR_Config::writeConfigFile fopen(‘C:\Windows\pear.ini’,’w’)indows\pear.ini): failed to open stream: Permission denied)”.

I have to re-open the cmd as administrator, so let’s continue to finish our installation by installing PHPUnit

9.    Open cmd (remember to open it as Administrator ) navigate to the php installation folder and run the following commands.
pear config-set auto_discover 1
pear install

10.    Wait while it install and follow the instruction.

11.    Restart your apache server.

That’s all you need to run a successful installation on windows 7. Though I have not tested but this process may also work in windows XP.


  1. Just tried it on Win XP at it worked perfectly. Thx for the guide, it was very helpful. I also did not have PEAR installed right away with PHP so this tutorial was the right one for me!!

  2. Hello,

    The steps seemed to have helped something (maybe just my understanding of PEAR).

    I to want to use PHPUnit in my Windows 7 64bit XAMPP test environment. And use it with the Yii framework.

    After following your instructions I get:

    C:\php>pear.bat install
    No releases available for package ""
    install failed

    C:\php>pear.bat uninstall
    phpunit/PHPUnit not installed

  3. Hi I’m getting this error.

    C:\wamp\bin\php\php5.5.12>pear install
    Attempting to discover channel “”…
    Attempting fallback to https instead of http on channel “”…
    unknown channel “” in “”
    invalid package name/package file “”
    install failed

1 Trackback / Pingback

  1. How to install PEAR and PHPUnit on windows. | Code Inspired

Leave a Reply

Your email address will not be published.