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
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
By default cURL looks for the ca bundle at
RPM installation of curl looks at
You can verify the correct path by using the following command.
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.
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
* Curl developers homepage
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.