This blog is about C++, CakePHP, Linux, PEAR, PHP, Pyrus, Apache, and MySQL and related topics.

Showing posts with label pear. Show all posts
Showing posts with label pear. Show all posts

Sunday, October 25, 2009

How To Install PEAR Services_Recaptcha-0.2.1

In this blog post I will show you how I installed PEAR Services_Recaptcha-0.2.1.

This is my setup:

  • Windows XP SP3
  • WampServer 2.0i
    • PHP version 5.3.0
    • Apache version 2.2.11
    • MySQL version 5.1.36
  • PEAR version 1.9.0
If you want to have a setup like mine just follow the instructions here. I have also explained How To Install PEAR with PHP 5.3.0 for those who don't want to install WampServer.

This is what we have to do:

  1. Load the pear console
  2. Login to the pear channel
  3. Services_Recaptcha-0.2.1 requires HTTP_Request2-0.4.1 which in turn requires Net_URL2-0.2.0 so we will install in this order: Net_URL2-0.2.0, HTTP_Request2-0.4.1, then Services_Recaptcha-0.2.1
  4. Test it is working
Step One: Load the pear console
Step One can be further broken down into two steps:

  1. Open the windows command line
  2. Switch to the PHP directory
1: Open the Command Prompt (also known as DOS and cmd.exe).
This is one way of doing it:

  • click start
  • click run
  • type cmd.exe in the 'open' field
  • click ok or press enter
The Command Prompt should now load and this is what it looks like:



2: Switch to the PHP directory.

This is the directory where php.exe is located. If you installed WampServer using default configurations then you will probably be going here: c:\wamp\bin\php\php5.3.0


On the command line type the following: cd c:\wamp\bin\php\php5.3.0

The prompt should now look like this c:\wamp\bin\php\php5.3.0




At this point it would be good to verify everything is going ok. Type 'pear' (without quotes) and hit enter. A list of pear commands should load.

This is what it looks like:




If this does not happen then check the following:


  • Did you spell pear correctly? This is the most obvious mistake so rule this one out first.
  • Are you in the right directory? Type 'dir' and a list of files should load. You know you are in the right directory if you see the following files:
    • php.exe
    • php.ini
    • pear.bat
    • PEAR 
    'PEAR' is a directory and not a file, but it should be there just the same.
  • Did you install PEAR (or did you install it correctly)? Go back and do it again

Step Two:  Login to the pear channel
At the prompt just type the following: pear login





  • Select '1' and enter a username
  • Select '2' and enter a password
  • Review and hit enter if everything is ok.
  • You are logged in

Step Three: Installations

 It's as simple as typing these three commands in succession:


  • pear install pear/Net_URL2-0.2.0
  • pear install pear/HTTP_Request2-0.4.1
  • pear install pear/Services_Recaptcha-0.2.1
The error messages are very helpful here. You can use them to verify which versions you should be installing. For example if you type 'pear install Services_Recaptcha' you will get an error telling you which version to install and which channel to install it from. Also if you type 'pear install pear/Services_Recaptcha-0.2.1' first you will get an error message telling you HTTP_Request2-0.4.1 should be installed and 'pear install pear/HTTP_Request2-0.4.1' will give you an error message that Net_URL2-0.2.0 should be installed.

It would also be a good idea to check http://pear.php.net to make sure you are installing the most recent version of Services_Recaptcha and its dependencies.

Step Four: Test it is working

To test it is working we will use some test code. Just cut and paste the following code and save as recaptcha.php and put this file in your DocumentRoot (c:\wamp\www if you installed WampServer with default configuration)

 This code comes from: http://code.google.com/p/services-recaptcha/wiki/RecaptchaExample2

Here is the code:



<?php

/**
 * Include the Services_ReCaptcha class
 */
require_once 'Services/ReCaptcha.php';

// you must get your API keys here:
// http://recaptcha.net/api/getkey
$publicKey  = 'your_public_key';
$privateKey = 'your_private_key';

// we instanciate our Services_ReCaptcha instance with the public key and the 
// private key
$recaptcha = new Services_ReCaptcha($publicKey, $privateKey);

// we are going to customize our Services_ReCaptcha instance
$recaptcha->setOption('secure', true);   // force the secure URL
$recaptcha->setOption('theme', 'white'); // use the white theme
$recaptcha->setOption('lang', 'fr');     // set language to french

// alternatively we could have done:
// $recaptcha = new Services_ReCaptcha($publicKey, $privateKey, true, array(
//     'secure' => true,
//     'theme'  => 'white',
//     'lang'   => 'fr'
// ));
// or:
// $recaptcha->setOptions(array('secure' => true, 'theme' => 'white', 'lang' => 'fr'));

// we use a proxy, so we need to configure it
$recaptcha->getRequest()->setConfig(array(
    'proxy_host' => 'localhost',
    'proxy_port' => 8118,
));

// if the form was submitted
if (isset($_POST['submit'])) {
    if ($recaptcha->validate()) {
        // the catpcha challenge response is ok, we display a message and exit
        echo "Challenge response ok !";
        exit(0);
    } else {
        // if the captcha validation failed, instead of letting the captcha 
        // display the error, we want to echo the error and exit
        echo $recaptcha->getError();
        exit(1);
    }
}

// we display the html form
?>
<html>
<head>
    <title>recaptcha test</title>
</head>
<body>
    <form method="post" action="">
<?php echo $recaptcha; ?>
        <hr/>
        <input type="submit" name="submit" value="Ok"/>
    </form>
</body>
</html>


Get the Recaptcha Keys


Next we go to  http://recaptcha.net/api/getkey and get a public and private key to insert into the script (around lines 10-11). For development purposes make global keys. In other words, we don't intend to use these keys in the real world and we don't want to set up new keys more than once for development purposes.

Load the page into your browser. This is what you should see:



That's it! You have successfully installed PEAR package Services_Recaptcha-0.2.1

Friday, October 23, 2009

How To Install PEAR With WampServer 2.0i

My last post described how to install PEAR with PHP 5.3.0 on a Windows XP machine.

Here, I will describe how I was able to get PEAR running with WampServer 2.0i

I like WampServer because it is the easiest way to install PHP, MySQL, and Apache on a Windows machine. Just go to the WampServer site, download and install the file. That's it.

Once it is installed if you want to add PEAR. This is what to do:

Note: I used the default folders when installing WampServer so if you want to follow me exactly then use the default folders. Otherwise, make note of your folders and make the necessary adjustments.

1. Go to this page and copy the content and create a file called go-pear.php. Save this file in the following directory: c:\wamp\bin\php\php5.3.0

2. Open the command line. Switch to the php directory (the one that has php.exe in it).

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

3. Type this command:

pear.php go-pear.php

4. Answer the installation questions. You might see a lot of warnings concerning deprecated methods. This is normal.

5. Update php.ini. This is the key to getting this right. There are two php.ini files. They are:

C:\wamp\bin\php\php5.3.0\php.ini
C:\wamp\bin\apache\Apache2.2.11\bin\php.ini

The phpinfo() page says the loaded configuration file is C:\wamp\bin\apache\Apache2.2.11\bin\php.ini but change I made to c:\wamp\bin\php\php5.3.0\php.ini were reflected on this page. Instead of figuring out which to use I decided to update both.

Do this to both php.ini files:

Open the php.ini file in any text editor. Notepad will do. In the "Paths and Directories" section find this line:;

Windows: "\path1;\path2"

Change the next line to the following:

include_path = ".;c:\wamp\bin\php\php5.3.0\pear"

Be certain to remove the ';' at the beginning of the line if one is present.

Save and close file.

Now it's time to verify if PEAR is properly installed. <--This article will show you how to do that.

Tuesday, June 2, 2009

Installing PEAR on Wampserver

This is a good article on installing pear package manager on wamp . I just wanted to add the following information which will be useful is you have the following setup:

Wampserver 2.0
PHP5.2.9-2
Apache2.2.11

After go-pear.bat concluded, I did not find php.ini in this folder: C:\wamp\bin\apache\apache2.2.11\php.ini instead I accessed php.ini from Wampserver itself. Click on Wampserver in the task tray. Move the cursor to PHP and all the PHP options will show. Click on php.ini then do a search (Control-F) to find include_path. Enter the new include_path. For my installation the include_path is: include_path=".;c:\wamp\bin\php\php5.2.9-2\pear" .Save and close php.ini. Go back to Wampserver and stop all services. Start all services, and put online. Now open php.ini and search for include_path. The new include_path should be there. Just like your article says type "pear" in the command prompt. If all the pear commands are listed, then you did it correctly.

The other thing that was slightly different was the location of the index.php.txt file for the PEAR_Frontend_Web package. In my installation it was located at C:\wamp\bin\php\php5.2.9-2\docs\PEAR_Frontend_Web\docs\index.php.txt

Followers