Friday 13 January 2012

How to setup PEAR on WAMP2.1 and Windows 7

This has been bugging me for ages now and I gave up trying to get it to work on my laptop but now I tried again at work and finally got it working. Yay!

Visit this page in your browser: http://pear.php.net/go-pear.phar

It will start a download. Move the go-pear.phar file to your C:\wamp\bin\php\php5.3.5\ directory

Now you need to put the pear executable into your system path. Right click on (My) Computer which can be accessed from the Desktop or Start button and select Properties. Click on Advanced System Settings and select the Advanced tab. Click the Environmental Variables button. Scroll down to find the Path variable and double click the value. Add a semicolon ";" at the end if there isn't one and then add this path: C:\wamp\bin\php\php5.3.5\

Save your changes.

Now open up the command line (Press the Start button and type in cmd) and go to C:\wamp\bin\php\php5.3.5\

Type in php go-pear.phar

Read the questions it asks you and type the stuff it tells you to continue. At the moment we're not too bothered with the variables it sets. When it's done it will write to the php.ini file in the current directory. This is NOT the php.ini file that WAMP uses. To see where the php.ini file is that WAMP uses you can create a phpinfo.php file in your www folder with <?php phpinfo(); ?> inside it and then run it from the browser, but I'll just tell you where it is instead - C:\wamp\bin\apache\Apache2.2.17\bin.

Open up the php.ini file that is in the current php5.3.5 directory with a text editor and scroll to the bottom to find these lines:

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

Copy and paste those to the bottom of the php.ini file in the Apache-based directory. Save your changes and  restart WAMP if you have it running.

Back in the command line type in pear config-create \wamp\bin\php\php5.3.5 pear.ini

Note the space between the path and the file name.

Now you may wish to set the paths of some of the configuration files if these are not already correct. To view the pear config settings type in pear config-show

This will give you an idea of which paths to amend. It will display a list in three columns, the first is the description/name of the setting, the second is its key and the third column displays the path.

In order to set the path correctly you need to supply the key as the first argument and the folder path as the second argument like so: pear config-set www_dir C:\wamp\bin\php\php5.3.5\www

Set the correct path for the keys www, data, cfg, docs and tests.

So now you are ready to run PEAR with your php.

First, have a go at installing a PEAR package like PHPUnit which is used in unit testing. The commands are:

pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit

Hopefully that should work fine. But if it doesn't like when I got back home to try installing it on my laptop. Try these commands and give it another go.

pear clear-cache
pear update-channels

With pear working, pear packages installed and your PHP include path including the pear directory you can write some good code. To include a pear-installed module type in include 'PHPExcel/PHPExcel.php'; for example.

I hope this stuff works for you too. I can't provide any support if it doesn't work for you because I don't know much about this stuff and I'm surprised I got it to work.

No comments:

Post a Comment