Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Well, after getting caught out recently with PEAR on a client installation, I thought it a good move to write a short tutorial for anyone who needs to install PEAR packages on their WAMP installation.

To start with, for the purposes of this blog, PEAR is a framework for implementing code libraries in PHP.  In other words, it prevents you from having to re-invent the wheel – always a nice thing!

The WAMP installation installs PHP, and at the same time installs the basic PEAR framework.  There is a directory called PEAR inside whatever folder contains PHP – on my particular installation the structure is php5.2.5\PEAR.  Taking a peek inside the PEAR folder will reveal it populated with the basic framework for PEAR.  Most of this you can ignore – I’m not going to detail installing this here – that seems to be well covered.  I just couldn’t find out how to actually enabvle the damn packages when I started, so I hope this is useful!

Checking Configuration

This is THE place where things can go PEAR-shaped, if you’ll allow the pun.  The PEAR folder must be included in the includes path within PHP.INI.  Open PHP.INI and find the line that starts with :

include_path =

or, if commented out

; include_path =

You need to add the path to your PEAR folder to the end of this string.  For example:

include_path = “.;e:\wamp\bin\php\php5.2.5\includes;e:\wamp\bin\php\php5.2.5\PEAR”

Now – it is CRUCIAL that there are NO spaces after or before the semi-colons that separate paths in this string.  If there are, quite simply, PEAR will not work.  Simple as that – any incldue path after such a space will NOT be searched by PHP.

Once you have modified the PHP.INI file, save it and restart your WAMP installation.

Installing a package

First of all, identify the package(s) that you want to install.  To do this, take a look at http://pear.php.net/packages.php, which lists the available packages for PEAR.  Identify the ones you’re interested in – for the same of example, let’s deal with a Mailer package.

Click on the relevant section of the Package list, and you’ll see a list of available Mail packages.  Select the one of interest – choose the package ‘Mail’ and click on it.  This will then display a page of details about the Mail package - and also the links to download, documentation, etc.  Now, there are two ways to download stuff, depending upon whether you have access to the command line program for PEAR or not.  This blog entry will assume you have – I’ll post the alternative instructions elsewhere.

To start with, make a note of the package name – ‘Mail’.

Check the Dependencies

Click on the ‘Download’ tab – you will see an entry someway down the page for ‘Dependencies’.  These are PEAR packages that you need to install for your chosen package to work.  Make a note of the dependencies – in this case, Net_SMTP.  Now click on that dependency, and check it’s dependencies – do this and you will see Net_Socket and Auth_SASL listed.  The latter is optional, so I won’t bother with that.  There are two other packages listed – however they’re part of the PEAR framework.

So, we now have a list of packages to download and install.  These are:

Mail, Net_SMTP, Net_Socket.  (We’ll ignore the Auth_SASL one for this example).

Whilst you can automate the acquisition of dependencies, it’s educational to do it ‘the hard way’ at first. :)   So that’s what we will do!

Start a Command Window

From your Windows Start menu, select the ‘Run’ entry, and enter ‘cmd.exe’.  Now change directory to the PHP directory.  On my machine this is:

E:\wamp\bin\php\php5.2.5

Once in there, type in pear list.  This will list the currently installed pear packages.  If it’s a new PEAR installation, there will be 3 packages listed 4 packages listed – PEAR, Archie_Tar, Console_Getopt and Structures_graph.

Now, type in pear update-channels.  this connects to the PEAR repository – where the PEAR files live – and updates your local installation with data needed to get packages.

Now, type in:

pear download Mail

pear install Mail

The former command gets a ZIP file containing the Mail package from the PEAR repository, and the latter will install the mail package.  Note the messages displayed on installation – the software warns you that you haven’t got the dependencies, and gives you a suggestion of a method of downloading the dependencies – which we’ll now use to get Net_SMTP an it’s dependencies.

We’ll also do this installation slightly different to the first one – thus showing there is more than one way to install a package.  Type in:

pear install -a Net_SMTP

No download this time – this will go off and get Net_SMTP, and all of it’s dependencies, and install them – all in one fell swoop!  The -a switch tells PEAR to get all the dependencies.

The files will be installed in to the PEAR folder.  Sometiems a PHP file will be placed in the folder itself – as happens with the DB package.  Other times a new folder will be created – like for Mail – and the PHP files placed in the new folder.

Testing the mailer.

Here is a piece of sample code to put in to a PHP file:

<?php
require_once "Mail.php";   

$from = "Sender <sender@example.com>";
$to = "Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nThis is a test!";   

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";   

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));   

$mail = $smtp->send($to, $headers, $body);   

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?> 

Set up your own parameters for the mail server and the authentication required – username and password, and the address of the recipient - and if you have successfully installed PEAR Mail then you should get a mail sent.  If you get any messages back refering to ‘No such file or directory’ then the chances are that the configuration of PHP.INI is a little screwed up. And there you have it!

18 Responses to “Installing PEAR packages on WAMP”
  1. Baran Khan says:

    Hi Joe,

    Thanks a million for such great tutorial…i have been scraping around my mind for it..and luckily found this one…u are such a gem…

    keep it up!

    baran

  2. Joe says:

    Thank you!

    Much appreciated – the nonsense with the space in the include_path kept me scratching my head for some time.

    Glad you found it useful!

  3. BKS says:

    Hello Joe,

    “From your Windows Start menu, select the ‘Run’ entry, and enter ‘cmd.exe’. Now change directory to the PHP directory. On my machine this is:

    E:\wamp\bin\php\php5.2.5

    Once in there, type in pear list.

    When I type pear list, and I sure am in the right directory, I don’t see anything in the cmd window.

    “Now, there are two ways to download stuff, depending upon whether you have access to the command line program for PEAR or not. This blog entry will assume you have – I’ll post the alternative instructions elsewhere.”

    Can I find the alternative instructions yet on your website?

    By thanking you in advance,

    BKS

  4. SnoT says:

    Oh !!!

    Really thanks for this tutorial, it’s very usefull !

    Good job man.

    SnoT.

  5. Mike says:

    Sadly the version of wamp I currently have only has a go-pear.bat and seemingly not a pear.bat type file.

    Command line options don’t seem to function for the go-pear command. I’m just about to download the latest version of wamp to see what’s going on.

    I noticed a pear-old.bat file which might suggest that pear.bat is no longer the way wamp does Pear installations? Any ideas?

    Thanks,
    Mike.

  6. Matt Pedersen says:

    YOU ARE THE MAN!!!

    I have spent HOURS getting mail to work with pear,
    NONE of the other sites tell you that you have to INSTALL
    Mail first … and if they do none of them really tell you HOW
    to do it …
    I can’t believe that EVERY step you listed worked 100%.

    Though I realized that using the shell from UnxUtils will NOT work – it must be cmd.exe

    thanks again!!!

  7. martin says:

    WASTED TUTORIAL!
    Dont work with pear list, and no instructions gived for the alternative method.

    Using newest wamp.

    0 points.

  8. Joe says:

    Hi Martin,

    Well, it worked for me, it’s worked for others, and I’m sorry it didn’t work for you.

    Hope you find an answer.

  9. Willabee says:

    Fantastic Joe, I struggled with this for some time until I found your article and have never looked back from using PEAR.

    To take this a step further:

    Send Mail Requiring SSL and Authentication

    In this case further setup is required:

    1. Check that php_openssl.dll exists in the ext folder.
    2. check: PHP.ini – extension=php_openssl.dll extension is enabled.

    Now the code needs extra arguments to be passed. Let’s assume we want to use a Google mail account:

    $host = ‘ssl://smtp.gmail.com’;
    $username = ‘user@googlemail.com’;
    $password = ‘pw’;

    $headers = array (
    ‘From’ => $from,
    ‘To’ => $to,
    ‘Subject’ => $subject
    );
    $smtp = Mail::factory(
    ‘smtp’,
    array (
    ‘host’ => $host,
    ‘IDhost’ => “gmail.com”,
    ‘port’ => 465,
    ‘auth’ => true,
    ‘username’ => $username,
    ‘password’ => $password
    )
    );

    $mail = $smtp->send($to, $headers, $body);

    Thanks again.

  10. Willabee says:

    Sorry Joe, lost my indentation, please fix during moderation and delete this comment. Should have used pre tags I guess?

  11. nanhe says:

    Hello Joe.
    your post is really nice.
    when i try ti install ilias open source with WAMP then pear problem ariease .
    thanks

  12. Ravi says:

    Hi joe,
    thaks for the tutorial..it’s really great…i followed all the steps above and installed the mail successfully…i can see the packages when i type pear list…but the problem is none of the examples based on the pear mail are not working for me…they’re always throwing the error Class ‘Mail’ not found …is there anything that i should do..?i’ve changed the include_path variable in php.ini files present in both the php folder and the one in the apache/bin folder…
    any help would be realllllly great…
    thanks again,
    ravi.

  13. Ravi says:

    sorry for bothering you…dont mind about my previous comment…i renamed my example file to something else from mail.php and it worked perfectly…
    also thanks to williabee for instructions on using authentication…
    and for others…the other method that was not mentioned in the original post that installs all the dependencies too is this:
    just type
    pear install –alldeps mail
    instead of the pear download mail,pear install mail and then installing the dependencies…
    ravi

  14. You rock, this is the best tutorial I’ve read to get the php pear smtp mail function working!

    I’d been trying every night for 3 weeks to get this working on my windows box!

    However my LAMP server with mail seemed go easier on my GNU/Linux Debian running Gnome box!

    I’ll take them both though!

    Thanks a million!
    (AIG Dollars not mine, arh..well I guess there mine too)

    Brett

  15. luke says:

    hi iv had this problem for weeks, although i am new too this its really buging me, please help i keep getting this error

    Failed opening required ‘Mail.php’ (include_path=’.;C:\php5\pear’

    i have windows vista, wamp, C:\wamp\bin\php\php5.3.0

    my include path in my php.configuration Settings ini file is like this ….

    ;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Paths and Directories ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;

    ; UNIX: “/path1:/path2″
    ;include_path = “.:/php/includes”
    ;
    ; Windows: “\path1;\path2″
    include_path = “.;c:\php\includes;C:\wamp\bin\php\php5.3.0\includes;C:\wamp\bin\php\php5.3.0\PEAR”
    ;
    ; PHP’s default setting for include_path is “.;/path/to/php/pear”
    ; http://php.net/include-path

    i installed wamp originally by going

    start->run->cmd

    cd C:\wamp\bin\php\php5.3.0

    then go-pear.bat

    then jus pressed yes and enter to all the questions

    is there somet iv done wrong…… please help me

  16. Joe says:

    Hi Luke,

    From what you’ve posted I can’t see anything that’s immediately wrong, BUT it may be worth while checking that the php.ini file that you’ve modified is actually the oine being used by PHP. Run a script with phpinfo() in it to get a list of the settings for PHP and check that the path is what you’ve entered.

    If it isn’t, then look for other PHP.INI files in your wamp installation and find teh one being used.

  17. chip says:

    Installing PEAR packages on WAMP post for thanx..

  18.  
Leave a Reply