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版,但我不知道這是否是問題
燦有人幫我弄清楚這個充滿魔鬼的地獄是怎麼回事?這真是讓我瘋狂!!!!!!
是頒發證書在您的cacert.pem列出的證書頒發機構? –
@MarcB我不知道 –