Installing PEAR and PHPUnit on WAMP and Windows 7

In the project that i am currently working on, we decided to use PHPUnit for doing our unit testing, and i found that it was not a straight forward thing to install that I had thought it would be. I had to start by installing Pear, and as soon as i type ‘go-pear’ in command prompt and pressed enter key I got my first error.

So here are the steps needed to install PEAR and PHPUnit error free on WAMP.

So let’s start with PEAR, please note my Wampserver is installed on drive ‘H’,  substitute it with your own. Also when this tutorial was written, php was in php5.3.0 folder, please use the path as per your current setup.

Steps to Install PEAR

1 ) Locate the “php.ini” file. In my case, I found it at this path:

H:\wamp\bin\php\php5.3.0\php.ini

Don’t use the WAMP system tray icon to edit this file.

2 ) Find the following line:

;phar.require_hash = On

3 ) Uncomment the “;phar.require_hash = On” line by removing the semi-colon.

4 ) Change “On” to “Off”.

phar.require_hash = Off

5 ) Save the file.

6 ) Now on command prompt type ‘go-pear’ . If it gives error, then download this file: http://pear.php.net/go-pear.phar put it in php folder and try this step again.

6 a)  If you installed phar file in the instruction above, then use command

 php go-pear.phar 

to install pear.

7 ) Select ‘local’ to the question asked.. and follow the instructions.

8 ) Now we need to edit the ‘php.ini’ again to add pear include path. Open ‘php.ini’ that we found in php5.3.0 folder and search for ‘go-pear’, you will see

;***** Added by go-pear 
include_path=".;H:\wamp\bin\php\php5.3.0\pear" 

;*****

Copy these three lines and paste it to ‘php.ini’ file which is located at :

H:\wamp\bin\apache\apache2.2.11\bin

9 ) Restart the apache, and you have PEAR installed on you machine.

But we are not done yet, to use ‘pear’ command in your command prompt from anywhere you will need to modify the windows environment variables.

10 ) Go to control panel –> system  and click on the ‘advanced system settings’ (it is on the left sidebar)

11 ) Click on the environment variables button and new/edit ‘PATH’ variable and add

‘H:\wamp\bin\php\php5.3.0’

in your path. You also need to add a new variable ‘PHP_PEAR_PHP_BIN’ and set the value to

‘H:\wamp\bin\php\php5.3.0\php.exe’

close you command prompt and open it again for these changes to take effect.

12 ) now type ‘pear’ on the command prompt and you should see pear command help printed for you.

Now that PEAR is installed, let’s install the PHPUnit.

Check out PHPCamp a place to share news, views and articles that are useful to PHP community.

Steps to install PHPUnit

1 ) On ‘C’ drive create a folder named ‘php5’

2 )Then on command prompt type:

 pear upgrade pear

2 ) Once PEAR  is updated, on command prompt type:

 pear channel-discover components.ez.no 

 pear channel-discover pear.phpunit.de

 pear channel-discover pear.symfony-project.com

4 )Finally type:

 pear install --alldeps phpunit/PHPUnit

And with this you should have PHPUnit installed on your system.

In my quest to install PHPUnit I found help from following articles

  1. Stackoverflow
  2. Wampserver forum
  3. Using Zend Framework blog

34 thoughts on “Installing PEAR and PHPUnit on WAMP and Windows 7

  1. Thank you very very very very very very very much now i am a happy person all works! I try to fix this problem almost a two week so woow with you help and great tutorial i do it in one hour !!!!!!!!!

  2. Perfect tutorial !!!

    The only thing I want to know is: what about C:php5 folder ?
    Should I remove it or I must keep it forever ?

    Days before I started my first YII framework’s star track test-driven script which requires installed PHPUnit. Now everything work. Thx

    Regards,

  3. I don’t normally leave comments, but thank you so very much. After much banging of head on the wall and hours of time wasted.

    Thank you!

  4. I followed your instructions and have tried few other posts including the instructions from http://www.phpunit.de/manual/3.6/en/installation.html, but no matter what I do I always get the following error when i use phpunit command from admin command prompt (on a 64bit Win 7 with PHP 5.3.3 install):

    Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in C:Program Files (x86)EasyPHP-.3.3.1phpphpunit on line 38

    Fatal error: require_once(): Failed opening required ‘PHP/CodeCoverage/Filter.php’ (include_path=’.;C:php5pear’) in C:Program Files (x86)EasyPHP-5.3.3.1phpphpunit on line 38

    Please suggest what can I do to resolve this issue

    Thanks!
    Anurag

  5. I wasted 3 days with installing this wampp and phpunit and stuffs… I lost all hope and at the moment of deleting my entire project directory (with my plans) I came to your post. Worked at first shot itself. Thanx a lot bro

  6. Tried this to install phpunit and al seemed to go fine but still cannot run it.

    ‘phpunit’ is not recognized as an internal or external command,
    operable program or batch file.

    is what i get from the command line.

    Pear tells me it is installed, when I check the phpunit folder, for me located at: C:wampbinphpphp5.3.0PEARPHPUnit
    there is no batch file in fact there is no file at all, just 2 folders, Extensions and Framework thats it so where is my phpunit.bat file??

  7. I cannot seem to find phpunit.bat, which is required by NetBeans for PHPUnit integration. Is there something else we must do?

  8. Pingback: without the 'a' » Configuring PHPUnit on Wamp 2.x

  9. Pingback: Installing PEAR and PHPUnit on WAMP and Windows 7 « CSS un HTML koda piemēri

  10. Bonjour

    Merci pour ce tutoriel, grâce a votre aide j’ai pu faire un bout de chemin en environnement Windows XP.
    La seule petite chose qui manque dans ton cheminement est le téléchargement de l’archive Structures_Graph-1.0.4.tgz, décompresser et copier le dossier Structure dans C:wampbinphpphp5.3.xPEAR.

    Merci vraiment sinon c’est un puzzle, et ton apport a été la portion la plus importante.

  11. Hi sir am getting following error after I hit -> pear install –alldeps phpunit/PHPUnit

    Starting to download PHPUnit-3.6.10.tgz (118,595 bytes)
    ……………………..done: 118,595 bytes
    Could not delete C:wampbinphpphp5.2.7phpunit, cannot rename C:wampbinphp
    php5.2.7.tmpphpunit
    ERROR: commit failed

    Can u please sort this problem out for me.. I have been banging my head for hours …

    note : 1. WAMP version 2.2 with php downgraded to php 5.2.7
    2. Ran cmd with admin rights.

  12. Pingback: PHPUnit – Pear – Windows 7 – PHP 5.4 - Michal "Twisťa" Haták

  13. If like me it doesn’t work saying that Structures/Graph is missing (windows 7 , php 5.3.5, apache 2.2.17) do the following :
    Go here and download the archive : http://download.pear.php.net/package/Structures_Graph-1.0.4.tgz
    When you extract this, you will get a file named “Structures_Graph-1.0.4″. Open it with winzip or winrar and extract again. Then you get a folder which contains ‘Structures’ folder. Copy the ‘Structures’ folder to C:wampbinphpphp5.3.5PEAR.

  14. Am facing the same issue while installing PHPUnit using pear-

    Could not delete C:PHPPearphpunit, cannot rename C:PHPPear.tmpphpunit
    ERROR: commit failed

    Has someone got similar issue and any steps for resolving the same.

    Have used cmd with Admin privileges, but still getting the error and also there is no point in deleting the folder manually as the.tmp has to be renamed post download completion of package.

    Please help

  15. Thanks, Thanks for this article, when I created dir C:php then command: pear install –alldeps phpunit/PHPUnit installed phpunit with success after many hours of trials

    VERY THANK YOU

Leave a Reply

Your email address will not be published. Required fields are marked *

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