Installing PHP and PHPUnit on Windows 7

Download PHP

Windows downloads of PHP are available here. If you are not sure of which version to get, check out this Stack Overflow page. I used the VC9 thread safe PHP 5.3.10 download.

Install PHP

Once you’ve downloaded the installer, run it and install PHP in C:\php\ (or wherever you like, only remember this path for later). Choose your webserver (or none if you don’t have a webserver installed) and select any additional components as needed, including PEAR.

Once PHP is installed open a command prompt. Check that PHP is set up correctly by running
php -v

It should give you output something like
PHP 5.3.10 (cli) (built: Feb 2 2012 20:27:51)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

If you don’t get this output something has gone wrong with the PHP install or in the modification of your environment variables. Get this fixed before proceeding with the guide.

Install PEAR

In the command prompt, switch to the directory that you installed PHP to by running
cd C:\php\

Then install PEAR by running

Press Enter to accept the default when it asks you “Are you installing a system-wide PEAR or a local copy?”
Press Enter again to accept the file layout.
Press Enter to finish.

Install PHPUnit

Run the following commands (they may take a while to update, be patient):
pear channel-update
pear upgrade-all
pear channel-discover
pear channel-discover
pear channel-discover
pear update-channels

To install PHPUnit, run
pear install --alldeps --force phpunit/PHPUnit

To test that PHPUnit was successfully installed, run
phpunit -v

If all is fine, it should print out something like PHPUnit 3.6.10 by Sebastian Bergmann followed by the help contents.


If you get a problem with PEAR refusing to install the dependencies for PHPUnit, try running this command: pear clear-cache. If the underlying problem is this error SECURITY ERROR: Will not write to C:\php\ as it is symlinked to C:\php\ - Possible symlink attack then clearing the cache should fix it.

If you get stuck with no helpful error messages while installing PHPUnit, check the PHP error log. To locate it, open your php.ini file (c:\php\php.ini) and look for a line like error_log="C:\Windows\temp\php-errors.log". Open the log file at the location specified and look at the bottom of the log for any recent errors. Copy the error message and Google for solutions.


  1. Kent Hawley says:

    I’m relatively new to PHP and totally new to PEAR.

    I’ve been using PHP 5.2.17 on Windows 7 with ZendServer CE (and Apache2) for a few months and wanted to add phpunit.

    PEAR and PHPUnit installs went smoothly. Thanks for your instructions.
    PHP -v and phpunit -v look good.

    1) However, when I run phpunit against unit\DbTest.php, it runs for a while, returns a blank line and exits gracefully. (I was expecting 2 or 3 lines with Test Success or Failure, elapsed time, etc).

    2) I thought about looking in error_log via php.ini. But I no longer see php.ini. Did the PEAR install hide it?

    I appreciate any insights you have.

  2. olive says:

    during starting to download PHPUnit-3.7.7.tgz installation PHPunit, I have the message :
    Could not delete C:\wamp\bin\php\php5.3.5\PEAR\phpunit, cannot rename C:\wamp\bin\php\php5.3.5\PEAR\.tmpphpunit
    ERROR: commit failed

    could you help me ?

  3. I got the following message:

    No releases available for package “”
    install failed

    To solve my problem I did this:

    pear remote-list -c phpunit
    pear update-channels
    pear clear-cache
    pear install –alldeps –force phpunit/PHPUnit

    Now it works!

  4. DJ says:

    I have spent 3 bleeding days trying unsuccessfully to get stupid pear to install php unit. God what a terrible tool! Your post helped me install php unit in 5 minutes 🙂 Thank you!!

  5. Vadorequest says:

    If, like me, you don’t have go-pear.bat in your php/ directory, download it here:
    use the console line like this for launch the script:
    php go-pear.phar

    (in the good directory, for me it was: C:\wamp\bin\php\php5.4.3\)
    All the next steps are good for me, no problem, I think ^^

    Good luck, very great tuto.

  6. Med says:

    J’ai un problème pour installer Pear sous Windows 7.
    la commande …>php go-pear.phar ou go.pear donne cette résultat :
    Could not open input file: go-pear.phar
    Merci d’avance

  7. SachinShukla says:

    First of all thank you so much for such a buttery notes on phpunit installtion->

    but somewhere i got the error after running go-pear command
    so right now i am using the wamp
    1->First i downloaded the pear phar file from http // and place it into my php/php(version directory).Then run a command via cmd
    1->php go-pear.phar
    2->put enter 2-3 times and also say yes somewhere between installation
    then i get error in this command
    pear install –alldeps –force phpunit/PHPUnit
    3->so first i run the command
    pear channel-discover
    4->then run the command
    pear install –alldeps –force phpunit/PHPUnit
    5->check installation with the command phpunit -v

Leave a Reply

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