Linux under PHP5.2 installation Curl extension supports HTTPS

Source: Internet
Author: User
Tags fpm soap ldap mcrypt

Problem:
LNMP servers running on the wire, the Curl modules installed for historical reasons only support HTTP and do not support HTTPS.
A similar request or post interface (applet) is not working properly.

First, the solution:
Compile and install curl, recompile PHP, and enable PHP's Curl module to support HTTPS.

Cd/data0/software
1. Download and install Curl
wget http://curl.haxx.se/download/curl-7.44.0.tar.gz
Tar zxvf curl-7.44.0.tar.gz
CD curl-7.44.0
./configure--prefix=/usr/local/curl--with-gssapi--ENABLE-TLS-SRP--with-libmetalink
Make && make install
2. Recompile PHP
PHP compilation parameters before finding the system
/usr/local/webserver/php/bin/php-i | grep Configure
./configure--prefix=/usr/local/webserver/php--with-config-file-path=/usr/local/webserver/php/etc--with-mysql=/ Usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-iconv-dir=/usr/local--with-freetype-dir-- With-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr/--enable-xml--disable-rpath--enable-discard-path- -enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--with-curl--with-curlwrappers--enable-mbregex--enable-fastcgi--enable-fpm--enable-force-cgi-redirect--enable-mbstring-- With-mcrypt--with-gd--enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-ldap- -WITH-LDAP-SASL--with-xmlrpc--enable-zip--enable-soap

Cancel original--with-curl
with:--with-curl=/usr/local/curl
cd/data0/software/php-5.2.17
# Go to the PHP installation package directory (note that the PHP version is the same as before)
./configure--prefix=/usr/local/webserver/php--with-config-file-path=/usr/local/ Webserver/php/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-iconv-dir= /usr/local--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr/--enable-xml-- Disable-rpath--enable-discard-path--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem-- Enable-inline-optimization --with-curl=/usr/local/curl --with-curlwrappers--enable-mbregex-- enable-fastcgi--enable-fpm--enable-force-cgi-redirect--enable-mbstring--with-mcrypt--WITH-GD-- Enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-ldap--WITH-LDAP-SASL-- With-xmlrpc--enable-zip--enable-soap

/USR/LOCAL/WEBSERVER/PHP/SBIN/PHP-FPM stop
#不确定是否要关闭, but just turn it off and edit it.
Make zend_extra_libs= '-liconv '
Make install
/USR/LOCAL/WEBSERVER/PHP/SBIN/PHP-FPM start

/usr/local/webserver/php/bin/php-i|grep Curl
# #有libcurl/7.44.0 openssl/1.0.1e the words. The instructions were successful.

Second, there is a way, the same server environment, using the socket to request or post data, the method is as follows:
function Socketrequest ($url, $data = "", $method = "", $cookieFile = "", $connectTimeout = 1) {
$return = ";
$matches = Parse_url ($url);

    !isset ($matches [' Host ']) && $matches [' host '] = ';    !isset ($matches [' path ']) && $matches [' path '] = ';    !isset ($matches [' query ']) && $matches [' query '] = ';    !isset ($matches [' Port ']) && $matches [' port '] = ';    $host = $matches [' Host ']; $path = $matches [' Path ']? $matches [' Path ']. ($matches [' query ']? ‘?‘.    $matches [' query ']: '): '/'; $port =!empty ($matches [' Port '])?    $matches [' Port ']: 443;        $conf _arr = Array (' limit ' = = 0, ' post ' + = $data, ' cookie ' = $cookieFile,    ' IP ' = = ', ' timeout ' = $connectTimeout, ' block ' = TRUE,);    foreach ($conf _arr as $k = + $v) ${$k} = $v;            if ($post) {if (Is_array ($post)) {$postBodyString = '; The foreach ($post as $k = = $v) $postBodyString. = "$k =". UrlEncode ($v).            "&";    $post = RTrim ($postBodyString, ' & ');    } $out = "POST $path http/1.0\r\n";        $out. = "Accept: */*\r\n";        $out. = "Referer: $boardurl \ r \ n";        $out. = "accept-language:zh-cn\r\n";        $out. = "content-type:application/x-www-form-urlencoded\r\n"; $out. = "User-agent:". $_sever[' Http_user_agent ']. "        \ r \ n ";        $out. = "Host: $host \ r \ n"; $out. = ' content-length: '. strlen ($post). "        \ r \ n ";        $out. = "connection:close\r\n";        $out. = "cache-control:no-cache\r\n";        $out. = "Cookie: $cookie \r\n\r\n";    $out. = $post;        } else {$out = "GET $path http/1.0\r\n";        $out. = "Accept: */*\r\n";        $out. = "Referer: $boardurl \ r \ n";        $out. = "accept-language:zh-cn\r\n"; $out. = "User-agent:". $_sever[' Http_user_agent ']. "        \ r \ n ";        $out. = "Host: $host \ r \ n";        $out. = "connection:close\r\n";    $out. = "Cookie: $cookie \r\n\r\n"; } $fp = @fsockopen (' ssl://'. $ip?    $ip: $host), $port, $errno, $errstr, $timeout); if (! $fp) {return ';        } else {stream_set_blocking ($fp, $block);        Stream_set_timeout ($fp, $timeout);        @fwrite ($fp, $out);        $status = Stream_get_meta_data ($FP); if (! $status [' timed_out ']) {while (!feof ($fp)) {if ($header = @fgets ($fp)) && ($header  = = "\ r \ n" | |                $header = = "\ n")) {break;            }} $stop = false; while (!feof ($FP) &&! $stop) {$data = Fread ($fp, ($limit = = 0 | | $limit > 8192 8192: $limit))                ;                $return. = $data;                    if ($limit) {$limit-= strlen ($data);                $stop = $limit <= 0;        }}} @fclose ($FP);    return $return; }}

Linux PHP5.2 Installing the Curl extension supports HTTPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.