BobCares :: Outsourced Web Hosting Support BobCares :: Outsourced Web Hosting Support   Call us Toll Free US: 1-602-288-9145
Toll Free: 1800-383-5193
Search site:

Contact us | Get custom quote
 
spacer.gif
spacer.gif  
15256 Reads
Add to Google AddThis Social Bookmark Button

Deploying libcURL with PHP

Posted on Monday, May 29, 2006 - 10:25 PM
  spacer.gif
 
LibcURL is a free and easy-to-use client-side URL transfer library. Its used often for getting files using URL syntax. cURL is an important library for PHP software such as Billing software like ModernBill ). LibcURL library allows these software to communicates with banks and payment gateways remotely.

In this article , we'll see how to install or upgrade libcurl to a new version ( 7.15.3 ) and then integrate it to the PHP running in the server. Following steps were successfully tested on a Plesk 7.5 server running on RHEL-3.

1 Install libcURL

LibcURL is under GPL. It can be downloaded from http://curl.haxx.se and installed freely.

1.1 Downloading and compiling of cURL

wget http://curl.haxx.se/download/curl-7.15.3.tar.gz
tar -xzf curl-7.15.3.tar.gz
cd curl-7.15.3
/configure
make
make install
By default, cURL is compiled with SSL support. If you've installed openssl in a custom directory, make sure that you give the "-with-ssl=<dir>" option while compiling.

On successful compilation, curl is installed to /usr/local/ directory.

1.2 Installing a CA cert bundle for curl

Accessing secure sites ( https ) through cURL requires a list of certifying authorities to be available for curl.

There are many a ways to get the latest ca-bundle, and the curl developers themselves provide one at

http://curl.haxx.se/ca/cacert.pem

By default cURL looks for the ca bundle at
/usr/local/share/curl/curl-ca-bundle.crt
RPM installation of curl looks at
/usr/share/ssl/certs/ca-bundle.crt
You can verify the correct path by using the following command.
$curl-config -ca
To install the latest ca-bundle , follow these steps.
$ wget http://curl.haxx.se/ca/cacert.pem
$ mv /usr/local/share/curl/curl-ca-bundle.crt /usr/local/share/curl/curl-ca-bundle.crt.old
$ mv cacert.pem /usr/local/share/curl/curl-ca-bundle.crt

1.3 Testing curl binary

To test the cURL binary, give a URL as its argument and see the output. Along with the webpage which it downloads, curl binary also lists statistics of data transfer. A sample output is as shown below.

$ curl http://www.yahoo.com > test.txt
% Total % Received % Xferd Average Dload Speed Upload Time Total Time Spent Time left Current Speed
100 32420 0 32420 0 0 14676 0 -:-:- 0:00:02 -:-:- 41571

2 Integrating with PHP

To integrate with PHP (assumed to be already running on the server), perform the following steps.

  • Download the php sourcecode from http://php.net
  • Untar and cd php-X.X.X
  • In your configure command , add "-with-curl=/usr/local''. Php looks for the include/curl/ inside the directory we give here, when configuring.
    ( tip: To make sure that existing configuration is not lost, get the configure command from phpinfo() )
  • make && make install.
  • restart apache.
Done !!!

2.1 Testing PHP with cURL

To test if php with cURL is working correctly, use the test script available at php.net/curl.

<?php

        $ch = curl_init("http://www.example.com/");
        $fp = fopen("example_homepage.txt", "w");
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_exec($ch); curl_close($ch); fclose($fp); ?>
To make sure that SSL sites are also working as expected, Change the URL to one using secure connection

3 References


Articles by Sojish Krishnan About the author: Sojish Krishnan works as Sr. Engineer in Bobcares.com. Sojish has worked in Bobcares for 4 years and is a passionate advocate of superior Customer support. He graduated Bachelors in Computer Science in 2001.

 
spacer.gif
spacer.gif spacer.gif spacer.gif spacer.gif
Online
There are 24 guests and 0 members online.
 
FAQ | AUP | Partners | Contact Us | RSS RSS | Sitemap
© Poornam Info Vision LLC. All rights reserved.
Call us Toll Free: 1800-383-5193