PEAR is a framework and system for installing a large set of libraries and classes that provide standardized and well-supported functions for PHP. PEAR stands for PHP Extension and Application Repository. Some of the popular packages (PEAR’s name for collections of libraries and classes) include tools for easily building HTML forms, simplified database access, and standardized access to e-mail functions. Almost any common web development function that you can think of probably has a PEAR package.
Even though PEAR is a framework, it’s not a framework in the traditional sense. Instead, each of the PEAR packages is more or less independent. Of course, you can use the various packages together to essentially build up your own framework. In one of our later tutorials, we’ll look at installing, configuring, and using a popular traditional model-view-controller (MVC) framework called CodeIgniter.
WampServer actually makes it quite simple to install the PEAR tools and packages, since it comes with a script to do the installation. The installation script must be run as an Administrator in Windows. To begin, open a Windows Command Prompt as Administrator by select Start | Programs | Accessories. Right-click on the Command Prompt menu item and choose Run As Administrator. When prompted, approve running as Administrator.
At the Administrator Command Prompt, change to the installation directory for PHP for your WampServer installation. Typically, this will be c:\wamp\bin\php\php5.2.11.
To install PEAR, at the Administrator Command Prompt, run go-pear.bat, which is a wrapper script for PEAR installer. In general, you can accept the default options for the install script, except for the following:
Public Web Files Directory (probably directory option #9) – Change to c:\wamp\www (your web “home” directory).
After installing the PEAR packages, the installer will prompt you to update php.ini so that the INCLUDE_PATH contains the path to the PEAR installation. Just accept the defaults again. We will change this setting after the installer completes. Enter this entire path, including the php.ini file name, at the installer prompt.
After the installer completes, you will need to update the INCLUDE_PATH variable in the php.ini file used by Apache. You can determine the location of this php.ini file by going to http://localhost/ and clicking on the phpinfo() link under Tools. On the phpinfo() page look for the Loaded Configuration File item; this is the php.ini file that you want to use. Open this php.ini file in a plain text editor, such as Notepad. Search for include_path in the file. Add the following line to the file:
Also, you will need to update your PATH environment variable to include this directory, as well, so that you can run the pear.bat update script from any directory. Open the Windows Control Panel and open the System Control Panel applet and go to Advanced tab. In the Advanced tab, click on Environment Variables… button. In the Environment Variables window, locate the PATH variable. Either the User or System PATH variable is fine, but preferably update the System PATH variable. In the Edit System Variable dialog box, navigate to the end of the Variable value field and add ;C:\wamp\bin\php\php5.2.11\PEAR. Note the semi-colon (;) at the beginning. Press OK and close the Environment Variables window and the Control Panel. For the change to take effect, you must close any Command Prompts that are open and open a new Command Prompt. (It is not necessary to open an Administrator Command Prompt, but you can use an Administrator Command Prompt, if desired.)
The installation program also creates a registry file named PEAR_ENV.reg in your PHP directory. This script sets the PHP environment variables. Double-click on this file to merge it into your registry. Accept any permission prompts that Windows displays.
That’s it for the install ation. To use PEAR, open a Windows Command Prompt and enter pear (or pear.bat). If you enter this command without any other parameters, PEAR will display the sub-commands that you can use. The main sub-command that you’ll use is install, which (obviously) installs the PEAR package that you specify. Also, you should probably become familiar with channel-add and channel-discover sub-commands so that you can install third-party PEAR packages (packages from sources other than the main PEAR repository).
If you want to try out your PEAR installation, you can install the PEAR Date package, which simplifies handling of dates in PHP. To do so, open a Command Prompt and enter:
pear install Date
Note PEAR package names are case-sensitive, so you must specify Date (and not date). If everything is set up properly, you should see something similar to the following displayed in the Command Prompt:
downloading Date-1.4.7.tgz ... Starting to download Date-1.4.7.tgz (55,754 bytes) .............done: 55,754 bytes install ok: channel://pear.php.net/Date-1.4.7
You can also check that the installation completed successfully by running:
pear info Date
You should see a plethora of detail (probably more than you wanted to know!) about the package.