Nov
06
2004

Running PEAR under PHP 4 and PHP 5 in Windows

This is a quick HOWTO which covers running multiple installations of PEAR under Windows. I am using Windows 2000 so this may not work under older Windows versions. The development of the PEAR installer is moving quite rapidly, so hopefully soon these instructions will no longer be needed and the functionality will be built into the installer.

I am taking for granted that you have a working version PEAR under PHP4, this includes setting up environment variables.

I am using the following paths:
PHP 4 base: c:\php
PHP 5 base: c:\php5

Getting Started

Before you do anything, make a backup of your current pear.ini file. The PHP5 installation process will overwrite this file, so you’ll need to have a copy if you want PEAR to continue working under PHP 4. You will also want to make a copy of pear.bat in your PHP 4 directory, if your PHP 4 directory is in your system PATH, then the PEAR installer will rename your PHP 4 pear.bat to pear.bat_old.

If you haven’t already, grab the latest version of PHP 5 and unzip it into c:\php5. You can save yourself a lot of trouble by making sure that php5 is working correctly by running php -v, if everything looks fine, then you are ready to roll. It is not a good idea to put c:\php5 in your system PATH at this point.

  1. Open up a command window and change directory to c:\php5.
  2. Start up the PEAR installer with “go-pear”
  3. After choosing your proxy options, you are presented with your path options. Using the defaults are suggested, however the php.exe path is not correctly selected, so enter ‘7′ and browse to your PHP 5 folder (Tip: Choose the folder, not the php executable).
  4. Once the change has been made and everything looks good hit enter to start the installation process.
  5. When the installation process finishes, you will be told to run a registry file to create new environment variables. Don’t do this.

Damage control

The PEAR installer has probably overwritten your PHP4 pear.ini file, to fix this copy the new pear.ini file into c:\php5 and restore the backup you made (you did make a backup, right?). If you no longer have pear.bat in your PHP 4 folder, then either restore from your backup, or rename the file pear.bat_old to pear.bat.

Getting to Work
Now you should have pear.bat and pear.ini in both c:\php and c:\php5. If you look at the contents of these two files you’ll see that the paths are hard coded into each file.

Open a new console window and make sure that the pear command is running correctly.
pear -V should output something like the following:

PEAR Version: 1.3.1
PHP Version: 4.3.7
Zend Engine Version: 1.3.0
Running on: Windows NT AARON 5.0 build 2195

and pear config-show should show paths to c:\php. If they show paths to c:\php5 you are either in c:\php and are running the PHP5 pear script (change to another directory and try again), or you haven’t yet removed the new pear.ini file from c:\php, or you ran the .reg file and have added the PHP 5 paths to your windows registry.

If your PHP 4 setup is still working properly, then move on to the next step. If you have problems sort them out before moving on.

Setting up PEAR under PHP 5
What we want to do is to access our PHP 4 version of PEAR with the ‘pear‘ command, and the PHP 5 version of PEAR with the ‘pear5‘ command. To do this we have to write a simple batch file, which creates the environment for PHP 5, and then runs the correct version of the PEAR installer.

In your c:\php (which I’m assuming is in your system PATH), create a new file called: pear5.bat and insert the following contents and save.

@echo off
setlocal
SET "PHP_PEAR_SYSCONF_DIR=C:\php5"
SET "PHP_PEAR_INSTALL_DIR=C:\php5\pear"
SET "PHP_PEAR_DOC_DIR=C:\php5\pear\docs"
SET "PHP_PEAR_BIN_DIR=C:\php5"
SET "PHP_PEAR_DATA_DIR=C:\php5\pear\data"
SET "PHP_PEAR_PHP_BIN=C:\php5\php.exe"
SET "PHP_PEAR_TEST_DIR=C:\php5\pear\tests"
SET "PHP_PEAR_EXTENSION_DIR=C:\php5\extentions"

%PHP_PEAR_BIN_DIR%\pear.bat -c %PHP_PEAR_BIN_DIR%\pear.ini %1 %2 %3 %4 %5 %6 %7 %8 %9
endlocal

You should now be all set. Test the PHP 4 version of pear with ‘pear -V‘ and the php5 version with ‘pear5 -V‘.

Make sure that everything is in order by installing a PHP5 only package (PHPUnit2 is a good choice). PHPUnit2 requires Benchmark, so try the following:

pear install Benchmark

to install benchmark into PHP 4. And then try to install PHPUnit2 into PEAR 5.

pear5 install phpunit2

If all is working correctly we should get a message that Benchmark is needed. Since you installed Benchmark in the PHP 4 version, you’ll need to install it again under PHP 5. Install both packages with:

pear5 install benchmark phpunit2

You will now also be able to set configuration options separately.

pear5 config-set preferred_state beta
pear config-set preferred_state alpha

To enable PEAR in your php scripts you will naturally have to change the include_path setting in your PHP5 php.ini file.

If all of this works out, then you are ready to rock and roll! If not send me an email and we’ll sort you out :)

Written by Aaron Wormus in: PHP |

1 Comment »

  • Aaron, that’s good. I needed that some weeks before, when I still was running PHP4 & 5 on the same machine – but now I switched completely to 5 ;-)

    Comment | 7/11/2004
  • Arturo

    Aaron, thanks a lot for the tips. But before I proceed, a couple of questions:

    (a) In the pear5.bat file, shouldn’t it be SET “PHP_PEAR_EXTENSION_DIR=C:\php5\ext” ?

    (b) Wouldn’t my pear.bat (the one for php4, the one in c:\php) be overwritten each time the base PEAR class is upgraded, even with the pear5 command?

    (c) If I previously ran the registry file in my php4 pear installation, should I delete from the registry the entries then created?

    Thanks again.

    Comment | 12/2/2006

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes