Just a quick and dirty walkthrough for the end goal of installing PHPUnit on a Windows 7 machine running WAMP. These steps should be fine for other versions of Windows and WAMP. Really the structure of the stack does not have a huge impact on the installation of both PEAR and PHPUnit.
PEAR stands for “PHP Extension and Application Repository” and is a distributed system of pre-built packages that extend the functionality of PHP very easily, often without the need for manual configuration changes to PHP itself. Think of it like an App Centre for PHP.
Since PHPUnit is one of these packages, we need to have this installed beforehand. NOTE: replace [version] with the version of PHP you are using:
- In Windows Explorer, go to your WAMP PHP installation folder (default will be C:\wamp\bin\php\php[version]).
- Create a new directory called “PEAR” here.
- Download the PEAR phar installer and place it in the new directory above.
- Fire up a cmd window (Start and search for “cmd”) as administrator
- Change to your new directory (default command will be “cd C:\wamp\bin\php\php[version]\PEAR”)
- Run the following command: “php go-pear.phar”
- The first thing that the installer will ask is whether you are installing a system wide copy of PEAR. Since you are probably working on a development machine, either is fine. Just press enter to install system wide.
- Next, the installer will show you a bunch of paths that it automatically calculated by using it’s current location on your disc.
[blockquote]NOTE: One problem I did run into here was that these paths were picking up paths for an old, and long gone, version of PHP. This was because I had installed PEAR before when that version of PHP was on my machine. As a result, there were some Environment Variables still in my system. If the same happens to you, make sure you remove all Environment Variables relating to PEAR.
- Right click “Computer”.
- Go to “Properties” -> “Advanced System Settings”.
- Hit the “Environment Variables” button at the bottom
- Delete everything relating to PEAR in the top box.
- Restart the installer above.
- If the paths are all in order, hit Enter. The installer will start doing it’s thing.
- A warning may pop up:
[code]WARNING! The include_path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified.[/code]
The installer will ask if you want it to write to it now, which you should do. But often the installer has picked out the wrong ini path anyway. Usually WAMP uses the php.ini file located in the Apache directory. In any case, make sure by going down to your WAMP system tray and going to PHP -> php.ini and doing a search for “include_path”. You want to alter the line that looks like this:
; Windows: “\path1;\path2”
;include_path = “.:/php/includes”
To look like this:
; Windows: “\path1;\path2”
include_path = “.;c:\wamp\bin\php\php[version]\pear”
- Finally, the installer is going to create a reg file in your PEAR directory to add Environment Variables to the system. Press enter to complete the installation
- Go to your new PEAR directory. You will see a new PEAR_ENV.reg file. Double click this and click Yes to add the new Environment Variables
- And finally, lets make life easier for ourselves by putting the path to PEAR in our System Path. Right click Computer -> Properties -> Advanced system settings and hit the Environment Variables button. This time, in the bottom window, find and double click the item called “Path”. In the popup, add this to the end of the current string: “;C:\wamp\bin\php\php[version]\PEAR”. Click OK twice and restart your cmd window.
Congrats, you just installed pear. Restart your WAMP server, and go pack to the cmd prompt to test. All you have to do to test is type “pear” and press enter. A list of options will appear (and not a “command not found” error). Keep this cmd prompt open for the next step.
- In your cmd prompt, navigate to your PHP directory. (default will be C:\wamp\bin\php\php[version])
- Run the following commands:
pear channel-discover components.ez.no
pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony.com
pear install –alldeps phpunit/PHPUnit
- Press enter and wait for pear to do it’s thing.
- Test that installation is complete by typing “phpunit” in your cmd window. A list of options should display.