How to install PEAR on Windows
PEAR stands for PHP Extension and Application Repository, which is a collection of PHP reusable classes. Using PEAR can save you great amount of time to code something that other people already coded, tested, and used. For example, if you need a HTML form validation routine, PEAR has it in its Validate Package.
Installing PEAR on Windows is a confusing task if you use the PEAR Installer. In this article, we're going to manually install PEAR and it will give you great control, flexibility, and opportunity to not only install it with a breeze, but also learn a bunch of knowledge about PHP, especially how to set up PHP include path.
Manually install PEAR on Windows What we need to install is actually PEAR Base System (a core package) which is called PEAR. All other packages use the core package to extend their functionalities. Later in this article, I will show you how to install and use a package that is not available in the core package.
Step #1: Download and set up PEAR core package.
Click the link above to open the download page. The file I downloaded was PEAR-1.9.1.tgz. Yours may be newer.
1.2 Once you have the package downloaded locally, extract it. You should have a folder called PEAR-X.X.X. In my case it's PEAR-1.9.1To unzip, you can use open source file archiver 7-Zip. You may have to unzip twice.
1.3 Drill down to folder PEAR-X.X.X until you find a folder called PEAR.
1.4 Move file PEAR.php and PEAR5.php to the PEAR folder.
1.5 Open PHP installation directory, e.g. C:\Program Files\PHP or C:\php
Installed PHP if you haven't done so.
1.6 Delete the folder PEAR in your PHP installation folder if it exists.
1.7 Copy the folder PEAR from the unzipped folder in step 1.3 and paste it to your PHP installation folder.
The PEAR folder is from step 1.3 above and it contains all the core classes we need.
Step #2: Create include path for PEAR.
To understand fully about how to create include path, refer to article Five ways to create include path for PHP.
To use all the classes provided by PEAR library, we need to set up an include path that can be used by PHP to easily call any PEAR class we want. There are a few ways to set up include path for PEAR. The most commonly used are:
Because we're installing PEAR on Windows, we can access and modify php.ini in C:\Program Files\PHP or C:\WINNT. Setting up include path via your .htaccess, or your site specific php.ini is discussed in article How to install PEAR on your shared web host.
2.1 Open php.ini which is at C:\Program Files\PHP or C:\WINNT directory.
2.2 Find the line include_path = ".;C:\php\includes" and comment it out by adding semi-colon ; in its front or remove it completely.
2.3 Add a new line as below.
Dependent on where your PHP installation folder is, it could be like
include_path = ".;C:\Program Files\PHP\PEAR"
include_path = ".;C:\php\PEAR"
If you have other include paths, you can define them here as well. Just separate each
with a semi-colon.
The include path created here will be used by PHP as implicit include path which means PHP will already know where to look for the path. So when use include statement include or require_once in a PHP page, you don't need to specify the path again.
For example, when we add code
2.4 After done, save and close php.ini file.
That's all to it. We have installed PEAR.
Step #3: Test if PEAR has been installed correctly.
The best way to test is actually use a PEAR class to do something. We will use PEAR's text_highlighter class to display colored PHP code on a web page.
The file I downloaded was Text_Highlighter-0.7.1.tgz
3.2 Unzip the package and rename the folder Text_Highlighter-0.7.1 to Text.
It looks like this after rename:
3.3 Copy and paste the folder Text to C:\php\PEAR folder.
This will add the Text Highlighter package to the PEAR code library directory and it's ready to be used.
3.4 Create the style sheet for highlighting code.
Find the file sample.css under C:\php\PEAR\Text and copy it over to your localhost directory.
On my machine, it's copied to C:\geeksengine\sample.css
3.5 Create a PHP page and save it as test-pear.php in your localhost.
On my machine, it's at C:\geeksengine\test-pear.php
3.6 Open test-pear.php in your text editor and add the following code. The code displays colored PHP code on a web page.
3.7 Run test-pear.php page.
Open your web browser and view web page http://localhost/test-pear.php. If you can see the colored PHP code as below, you have successfully installed PEAR base library.
To use any other packages in PEAR library, just download and add them to C:\php\PEAR directory. To use PEAR on your website, please refer to
How to install PEAR on your shared web host.
Copyright © 2016 GeeksEngine.com. All Rights Reserved.
This website is hosted by LunarPages.
No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.