Select Page

Deploying libcURL with PHP

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.

Hire Bobcares Linux Server Administrators
Get super reliable servers and delighted customers

See how we do it!

 

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
( To get the latest version goto http://curl.haxx.se/download.html )
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 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.

To make sure that SSL sites are also working as expected, Change the URL to one using secure connection

3 References

* Curl developers homepage

* PHP.net



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.



PHPServer Support
PHP

3 Comments

  1. Hi,

    Now it released new version 7.19.2. Can you please add this to your article………

    Thanks and Regards,
    Naizam.H

  2. Thank you Naizam for pointing it out.

    I’ll update the relevant section.

  3. Hi Sojish,

    Would you mind helping me compiling php with cURL?
    I am new to this and I have a VPS to do tihs. I have already installed cURL. just need to recompile php with it.

    Please email me directly.

    Thanks

Bobcares
Bobcares is a server management company that helps businesses deliver uninterrupted and secure online services. Our engineers manage close to 51,500 servers that include virtualized servers, cloud infrastructure, physical server clusters, and more.
MORE ABOUT BOBCARES