Installing/Upgrading libCurl And Integrating with PHP
Technical
Thursday, 20 April 2006 14:48
Libcurl is a free and easy-to-use client-side URL transfer library used often for getting files using URL syntax. Curl is an important library for PHP softwares such as billing softwares (eg: ModernBill ) which communicates with banks and payment gateways often.Libcurl helps to communicate with remote servers with ease.

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.

Contents

1 Installing libcurl

Libcurl is under GPL & it can be downloaded from http://curl.haxx.se & 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=" 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 gives a 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 ( which is assumed to be already working in 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 , you can the test script given at http://php.net/curl .

        $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);

?>
Change the url to one using secure connection to make sure that SSL sites are also working as expected.

3 References

Sojish Krishnan 2006-04-21
Comments
Add New
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."