Saturday, January 24, 2015

Upgrading Ubuntu 12.04.x LTS (precise pangolin) cURL and libcurl from 7.22.0 to 7.39.0

Upgrading Ubuntu 12.04.x LTS (precise pangolin) cURL and libcurl from 7.22.0 to 7.39.0

Upgrading 12.04 curl to 7.39.0 can not be done using package system. In this how-to I will show how to upgrade by manually compiling and binding PHP.

[STEP 1] Download new version 7.39.0 from cURL website:

cd /usr/local/src
wget http://curl.haxx.se/download/curl-7.39.0.tar.gz
tar -zxvf curl-7.39.0.tar.gz
cd curl-7.39.0

[STEP 2] Configure, make and install:

./configure --enable-optimize --enable-warnings --disable-ares --enable-shared --enable-static=no --enable-http --enable-ftp --disable-ldap --disable-ldaps --disable-rtsp --enable-proxy --disable-dict --disable-telnet --disable-tftp --enable-pop3 --enable-imap --enable-smtp --disable-gopher --disable-ipv6 --enable-threaded-resolver --enable-verbose --disable-sspi --enable-crypto-auth --disable-ntlm-wb --disable-tls-srp --enable-cookies --disable-soname-bump --without-librtmp

make
make install

[STEP 3] Remove existing installation (if installed via apt-get):

apt-get remove curl
apt-get autoremove


[STEP 4] Confirm cURL got installed:

ls -lsa /usr/local/bin
ls -lsa /usr/local/lib

Note: you should see curl binary executable with today's date.


[STEP 5] CREATE SOFT LINK FOR 'curl' EXECUTABLE IN /usr/bin

ln -s /usr/local/bin/curl /usr/bin/curl


[STEP 6] VERIFY DEFAULT CURL is now using new version:

curl -V


Step 6 completes the upgrade of cURL and libcurl. You can stop here if you do not need to upgrade other softwares using the cURL on your computer / server.

If you are using PHP, you have to continue with the steps below to rebind PHP with your new cURL binaries.


---------------  [PHP BINDING]  ----------------------------------

The instructions below will rebind your PHP to your newly upgraded cURL and libcurl.  I am using PHP-FPM. However this how-to guide should work similarly for mod-php.  The steps below are optional if you are not using PHP.

[STEP 7] UPGRADE PHP cURL BINDING

(mine was version 7.22.0)

apt-get install php5-curl


( this may also upgrade your PHP from 5.4.x to newest 5.4.x - at the time of this writing, I was upgraded to PHP 5.4.36-1 )

curl -V

should show:

curl 7.39.0 (x86_64-unknown-linux-gnu) libcurl/7.39.0 OpenSSL/1.0.1 zlib/1.2.3.4
Protocols: file ftp ftps http https imap imaps pop3 pop3s smtp smtps
Features: AsynchDNS Largefile NTLM SSL libz


[STEP 8[ RESTART PHP5-FPM + WEBSERVER

service php5-fpm restart
service nginx restart

------------------------------------------------------------

CHANGES NEEDED IN PHP CODE

If you are using curl option CURLOPT_SSLVERSION, it is recommended comment this out (do not use this option).
By default (leaving unset), PHP's curl extension should automatically negotiate with remote server the best protocol to use.

I have tried to set CURLOPT_SSLVERSION to CURL_SSLVERSION_TLSv1 and got error about CURL_SSLVERSION_TLSv1 not defined.

This is because CURL_SSLVERSION_TLSv1 was not defined before PHP 5.5. Since I am not going to upgrade to 5.5+ just because of this issue, I decided to just NOT set the  CURLOPT_SSLVERSION option.

In case you still want to set CURLOPT_SSLVERSION to whatever value you want, here are the define values:

Tip: the value in the parentheses is the constant's value.

CURL_SSLVERSION_DEFAULT (0)
CURL_SSLVERSION_TLSv1 (1)
CURL_SSLVERSION_SSLv2 (2)
CURL_SSLVERSION_SSLv3 (3)
CURL_SSLVERSION_TLSv1_0(4)
CURL_SSLVERSION_TLSv1_1 (5) 
CURL_SSLVERSION_TLSv1_2 (6)