Curl with PHP 5.2.9-2 and Apache 2.2.11 on Windows XP

This is a quick follow up post from Tony Spencers post “cURL with PHP and Apache on Windows.” I’d like to thank him for sharing his knowledge.

The reason i wanted to post this is to clear up any confusion you about getting Curl to work on Windows XP (with PHP 5.2.9-2 and Apache 2.2.11). Most likely this solution will work with all versions of PHP5 and Apache 2.2.x and if you are running XAMPP you can check how easy it is to >> enable << .

Getting Curl to Work!!

  1. First thing to do is to have the development environment installed locally on your computer. I have one at the office with installed without the installer and one here at home with the installer. For all intensive purposes lets concentrate on using php/apache installed with the MSI installer. If you got that going thats great, if not head on over to this >> Tutorial to install your local development << (the manual way with the installer) If you got it installed already head on over to the next point
  2. Next thing you need to do (after your installation) is to check your phpinfo() file. If you don’t have one make one and load it up on your local web-server. It should look like the screen below:
    Php.ini showing Curl extension

    If you don’t see your Curl extension in phpinfo() after trying to find it I suggest you install php again using the installer. Make sure your ENABLE all extensions/features in your installation as you will get an option to do so. (install all features please) If you explore the extension features in your install dialogue box you will see CURL there. This my friends is the key to the problem. If the installer gives you the option for less headache then use it. Did I mention that you can also rerun the installer and choose “Change”, then add the CURL extension?!

  3. Once you have installed properly and find the Curl extension in your phpinfo() screen make sure to copy these files from your PHP root directory (mine was D:\Program Files\PHP) to your c:\windows\system32:
    libeay32.dll
    ssleay32.dll

    Also make sure that a copy of php5ts.dll is also in your Apache/bin directory
  4. Last step is to uncomment this line curl: extension=php_curl.dll in your php.ini file. That should do it for you and hopefully everything worked out right!
  5. To test that Curl is actually working use this snippet of code and drop it in to your server root (usually htdocs):
    [php]

    [/php]

    Try this as well to display feeds from your blog (where $sXML = show_feeds(‘put the url of your blog here/atom’)
    [php]
    foreach($oXML->entry as $oEntry) {
    echo $oEntry->title . “\n”;
    }
    ?>
    [/php]

  6. If you see the the rss feed of Google then you are done! Change the output to ‘html’ and you will see the RSS feed displayed properly in html.

Scripting Twitter with cURL via Command Line

Ok the above explanation shows you how to use Curl and PHP together to build applications based on API’s that you would like to hook into. It doesn’t mean that you have Curl installed in your command like prompt where you can actually see the XML.

To do that is quite simple. Go over to http://curl.haxx.se/download.html and download the the Win32 Generic (7.19.4) by Dirk Paehl. Go ahead and extract it to a local folder (I extracted it to D:\Program Files\Curl).

Next open up the command prompt and cd into the same directory you extracted it into. Now just type in curl at the prompt to make sure the command is recoginized
Curl at the CMD line

If you want to easily overcome the shortcomings of Twitter’s API us this command below:

curl --basic --user username:password --data status="Checking out Curl!!" http://twitter.com/statuses/update.xml
//replace username:password with your user name and password

You should end up with this below:
Scripting status update

So by now you should have a good idea of how Curl works with Apache and PHP as well as on the command line. The way i explained above should work straight out of the box. Good Luck!

5 Comments Curl with PHP 5.2.9-2 and Apache 2.2.11 on Windows XP

  1. Pingback: Curl with PHP 5.2.9-2 and Apache 2.2.11 on Windows XP

  2. Eric

    Thanks for the information. All works great on a simple vista machine running Apache server 2.2 php 5.2.10 Both examples work fine.
    When trying a secure website https://www.web.com, I get nothing.
    0 ){
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
    echo curl_error($ch);
    } else {
    curl_close($ch);
    echo $response;
    }
    ?>
    Should be getting this response from server:

    If I rem the curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    I get an error
    SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

    Couple of things to note. I installed curl 7.18.2
    When I run the phpinfo().
    libcurl/7.19.4 OpenSSL/0.9.8i zlib/1.2.3

    It’s amazing I made it this far………and it works.
    With the new release of php did I even need to download curl?
    Do I need to use the curl.exe to build a new ????

    Reply
    1. admin

      Hey Eric. No you don’t even need to install Curl with the new release, but just make sure you have all the libs checked with your first install. I’ve had problems with the OpenSSL version (both local and server), but check which version of CURL your web server supports; that might do the trick. Also double check your php.ini and apache config files.

      Reply
  3. Peter

    Very nice example. I was lucky to find it.
    I was seriously rolling eyes when I seen that “simple” installation instruction on curl project site.

    Thank you Ahad

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *