2016-09-30 86 views
0

我在過去的2天裏一直在爲這個錯誤而煩惱。我搜索了數百次,似乎沒有任何工作。ubuntu 14.04 php 7 curl無法獲得發行者證書

我有通過命令行運行php 7的ubuntu 14.04。 這是我運行的代碼:

try { 
    $ch = curl_init(); 

    if (FALSE === $ch) 
     throw new Exception('failed to initialize'); 

    curl_setopt($ch, CURLOPT_URL, 'https://infoconv.receita.fazenda.gov.br/ws/cpf/ConsultarCPF.asmx?wsdl'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_CAINFO, '/etc/php/cacert.pem'); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
    //curl_setopt(/* ... */); 

    $content = curl_exec($ch); 

    if (FALSE === $content) 
     throw new Exception(curl_error($ch), curl_errno($ch)); 

    // ...process $content now 
} catch (Exception $e) { 
    print_r($e); 
} 

,這是輸出(命令行):

Exception Object 
(
    [message:protected] => SSL certificate problem: unable to get issuer certificate 
    [string:Exception:private] => 
    [code:protected] => 60 
    [file:protected] => /home/andre/Projects/p/lib/EB/Inf/teste.php 
    [line:protected] => 40 
    [trace:Exception:private] => Array 
     (
     ) 

    [previous:Exception:private] => 
) 

注意,錯誤是「無法獲得發行者證書」,而不是「無法獲得本地頒發者證書「就像這種類型的大多數錯誤(我不知道這兩個消息是否說同一件事)。

好吧,當我運行:

php --info | grep .ini 

在命令行中,我得到:

Configuration File (php.ini) Path => /etc/php/7.0/cli 
Loaded Configuration File => /etc/php/7.0/cli/php.ini 
Scan this dir for additional .ini files => /etc/php/7.0/cli/conf.d 
Additional .ini files parsed => /etc/php/7.0/cli/conf.d/10-opcache.ini, 
/etc/php/7.0/cli/conf.d/10-pdo.ini, 
/etc/php/7.0/cli/conf.d/15-xml.ini, 
/etc/php/7.0/cli/conf.d/20-calendar.ini, 
/etc/php/7.0/cli/conf.d/20-ctype.ini, 
/etc/php/7.0/cli/conf.d/20-curl.ini, 
/etc/php/7.0/cli/conf.d/20-dom.ini, 
/etc/php/7.0/cli/conf.d/20-exif.ini, 
/etc/php/7.0/cli/conf.d/20-fileinfo.ini, 
/etc/php/7.0/cli/conf.d/20-ftp.ini, 
/etc/php/7.0/cli/conf.d/20-gettext.ini, 
/etc/php/7.0/cli/conf.d/20-iconv.ini, 
/etc/php/7.0/cli/conf.d/20-json.ini, 
/etc/php/7.0/cli/conf.d/20-phar.ini, 
/etc/php/7.0/cli/conf.d/20-posix.ini, 
/etc/php/7.0/cli/conf.d/20-readline.ini, 
/etc/php/7.0/cli/conf.d/20-shmop.ini, 
/etc/php/7.0/cli/conf.d/20-simplexml.ini, 
/etc/php/7.0/cli/conf.d/20-soap.ini, 
/etc/php/7.0/cli/conf.d/20-sockets.ini, 
/etc/php/7.0/cli/conf.d/20-sysvmsg.ini, 
/etc/php/7.0/cli/conf.d/20-sysvsem.ini, 
/etc/php/7.0/cli/conf.d/20-sysvshm.ini, 
/etc/php/7.0/cli/conf.d/20-tokenizer.ini, 
/etc/php/7.0/cli/conf.d/20-wddx.ini, 
/etc/php/7.0/cli/conf.d/20-xmlreader.ini, 
/etc/php/7.0/cli/conf.d/20-xmlrpc.ini, 
/etc/php/7.0/cli/conf.d/20-xmlwriter.ini, 
/etc/php/7.0/cli/conf.d/20-xsl.ini 
user_ini.cache_ttl => 300 => 300 
user_ini.filename => .user.ini => .user.ini 
Classes => AppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, CallbackFilterIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, GlobIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException 
open sourced by => Epinions.com 

所以,加載的配置文件是在/etc/php/7.0/cli/php的.ini 這是該文件與捲曲配置的片段:

[curl] 
; A default value for the CURLOPT_CAINFO option. This is required to be an 
; absolute path. 
curl.cainfo = /etc/php/cacert.pem 

[openssl] 
; The location of a Certificate Authority (CA) file on the local filesystem 
; to use when verifying the identity of SSL/TLS peers. Most users should 
; not specify a value for this directive as PHP will attempt to use the 
; OS-managed cert stores in its absence. If specified, this value may still 
; be overridden on a per-stream basis via the "cafile" SSL stream context 
; option. 
openssl.cafile=/etc/php/cacert.pem 

我cacert.pem文件更新和位於給出的路徑:

╰─$ cd /etc/php/ && ls -al 
total 276 
drwxr-xr-x 3 root root 4096 Set 26 17:25 . 
drwxr-xr-x 149 root root 12288 Set 30 15:37 .. 
drwxr-xr-x 4 root root 4096 Set 26 10:48 7.0 
-r--r--r-- 1 root root 261644 Set 30 14:54 cacert.pem 

我有我的cacert.pem從https://curl.haxx.se/ca/cacert.pem 當我運行:

php -r "print_r(get_loaded_extensions());" 

在命令行中,我得到:

Array 
(
    [0] => Core 
    [1] => date 
    [2] => libxml 
    [3] => openssl 
    [4] => pcre 
    [5] => zlib 
    [6] => filter 
    [7] => hash 
    [8] => pcntl 
    [9] => Reflection 
    [10] => SPL 
    [11] => session 
    [12] => standard 
    [13] => PDO 
    [14] => xml 
    [15] => calendar 
    [16] => ctype 
    [17] => curl 
    [18] => dom 
    [19] => exif 
    [20] => fileinfo 
    [21] => ftp 
    [22] => gettext 
    [23] => iconv 
    [24] => json 
    [25] => Phar 
    [26] => posix 
    [27] => readline 
    [28] => shmop 
    [29] => SimpleXML 
    [30] => soap 
    [31] => sockets 
    [32] => sysvmsg 
    [33] => sysvsem 
    [34] => sysvshm 
    [35] => tokenizer 
    [36] => wddx 
    [37] => xmlreader 
    [38] => xmlrpc 
    [39] => xmlwriter 
    [40] => xsl 
    [41] => Zend OPcache 
) 

所以,我已openssl和捲曲啓用。

我做的唯一不同的事情就是運行:

sudo apt-get platform-update 

,然後我的PHP(CLI)得到了更新到第7版,但我不知道這是否是問題

燦有人幫我弄清楚這個充滿魔鬼的地獄是怎麼回事?這真是讓我瘋狂!!!!!!

+0

是頒發證書在您的cacert.pem列出的證書頒發機構? –

+0

@MarcB我不知道 –

回答

0

保存下面的代碼爲:cert.pem,然後將cert.pem的絕對路徑在下面的行樓下:

curl_setopt($ch, CURLOPT_CAINFO, '/etc/php/cert.pem'); 

試試吧。

-----BEGIN CERTIFICATE----- 
MIIHgzCCBWugAwIBAgIEANB0wjANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC 
QlIxEzARBgNVBAoTCklDUC1CcmFzaWwxNjA0BgNVBAsTLVNlY3JldGFyaWEgZGEg 
UmVjZWl0YSBGZWRlcmFsIGRvIEJyYXNpbCAtIFJGQjEtMCsGA1UEAxMkQXV0b3Jp 
ZGFkZSBDZXJ0aWZpY2Fkb3JhIFNFUlBST1JGQnY0MB4XDTE2MDgwNDExMjM1NVoX 
DTE3MDgwNDExMjM1NVowgbMxCzAJBgNVBAYTAkJSMRMwEQYDVQQKEwpJQ1AtQnJh 
c2lsMTYwNAYDVQQLEy1TZWNyZXRhcmlhIGRhIFJlY2VpdGEgRmVkZXJhbCBkbyBC 
cmFzaWwgLSBSRkIxETAPBgNVBAsTCEFSU0VSUFJPMRowGAYDVQQLExFSRkIgZS1T 
ZXJ2aWRvciBBMTEoMCYGA1UEAxMfaW5mb2NvbnYucmVjZWl0YS5mYXplbmRhLmdv 
di5icjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALAB4W8qNlNQiR37 
lFA8iMM+DrFPDXuz9EY9MpR/ZFP/yIH0k5tgcm8IvI7Nfl3erIp9UUIP19yfZ/MJ 
TkcGzyLDUDOOOA06XE10MYOil6xTeboPd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