Custom Search
 


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.

1.1 Download 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.

Download PEAR Base System

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.1

To 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.

unzipped PEAR package

1.4 Move file PEAR.php and PEAR5.php to the PEAR folder.

Move PEAR.php file

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.

Delete PEAR folder

1.7 Copy the folder PEAR from the unzipped folder in step 1.3 and paste it to your PHP installation folder.

C:\Program Files\PHP

OR

C:\php

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:

  1. Set up include path in php.ini

  2. Set up include path in .htaccess

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"

OR

include_path = ".;C:\php\PEAR"

Include path for PEAR

If you have other include paths, you can define them here as well. Just separate each with a semi-colon.
For example. include_path = ".;C:\php\PEAR;C:\geeksengine\inc"

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 <?require_once("Text/Highlighter.php");?> in a PHP page, it knows that the file is at C:\php\PEAR\Text\Highlighter.php. There is no need to specify C:\php\PEAR because it has been defined in php.ini as the default include path.

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.

3.1 Download PEAR Text_Highlighter package

The file I downloaded was Text_Highlighter-0.7.1.tgz

Download Text Highlighter package

3.2 Unzip the package and rename the folder Text_Highlighter-0.7.1 to Text.

It looks like this after rename:

Rename text highlighter folder

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.

Text highlighter folder

3.4 Create the style sheet for highlighting code.

Text highlighter sample.css

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.

<?
echo "<link rel='stylesheet' type='text/css' href='sample.css'>";

// Include Highlighter class
require_once("Text/Highlighter.php");

// This is the code we want to display
$code "<?
// This is a test page for PEAR Text_Highlighter package
\$message = \"Hello, world!\";

echo \$message;
?>"
;

// What to display - PHP code
$what "php";

// Define the class
$highlighter =& Text_Highlighter::factory($what);

// Call highlight method to display the code to web browser
echo $highlighter->highlight($code);
?>

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.

Test code highlighter

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© GeeksEngine.com



Related Articles:

1.Steps to install PHP 5.x on Windows as a development machine
2.How to install Apache 2.x web server on Windows
3.How to connect two different versions of MySQL server on the same computer
4.How to configure MySQL server 5.1 on Windows
5.How to install MySQL server 5.1 on Windows with screenshots
6.Five ways to create include path for PHP
7.How to use Date and Time data as integer value in PHP and MySQL
8.How to use Apache Virtual Host to run multiple local websites on Windows
9.Install all PEAR packages by yourself
10.How to use PHP and Microsoft SMTP Virtual Server to send emails
11.How to install PHP server-side scripting language on Windows
12.How to install Apache 1.3 web server on Windows
13.How to install two different versions of MySQL server on the same PC
14.How to configure MySQL server 4.1 on Windows
15.How to install MySQL server 4.1 on Windows with screenshots
16.Export Northwind Access database to MySQL via ODBC


Other Recent Articles from the WAMP & LAMP category:

1.Steps to install PHP 5.x on Windows as a development machine
2.How to install Apache 2.x web server on Windows
3.How to connect two different versions of MySQL server on the same computer
4.How to configure MySQL server 5.1 on Windows
5.How to install MySQL server 5.1 on Windows with screenshots
6.How to upgrade from PHP4 to PHP5
7.How to load time zone data for MySQL on Windows
8.How to use Apache Virtual Host to run multiple local websites on Windows
9.Install all PEAR packages by yourself
10.How to use PHP and Microsoft SMTP Virtual Server to send emails
11.How to install PHP server-side scripting language on Windows
12.How to install Apache 1.3 web server on Windows
13.How to install two different versions of MySQL server on the same PC
14.How to configure MySQL server 4.1 on Windows
15.How to install MySQL server 4.1 on Windows with screenshots
16.How to set up DSN in ODBC Data Source Administrator on Windows
17.Export Northwind Access database to MySQL via ODBC

Copyright © 2014 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.

 
Home | Feedback | Terms of Use | Privacy Policy