Lee*_*cks 7 php apache macos curl
Mac OSX El Capitan,默认apache安装在localhost上,brew安装了php70.以下代码使用cli(php -f test.php),但从apache运行时我得到以下内容.
SSL certificate problem: Couldn't understand the server certificate format
Run Code Online (Sandbox Code Playgroud)
使用"http"URL在两者中都可以正常工作.在Ubuntu机器上相同的设置工作正常.在干净安装El Capitan之前我有这个工作,我依旧记得有关Mac OSX和openssl的卷曲,但在这里找不到区别.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.example.com/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Run Code Online (Sandbox Code Playgroud)
ste*_*ank 10
我有同样的问题,经过大量的搜索后找到了解决方案......
我正在使用,php56
但我认为没有理由这也不适用php70
.
首先检查PHP cURL库是否使用内置的Mac OS(X)版本的SSL:
php -i | grep "SSL Version"
如果你得到SSL Version => SecureTransport
它,它使用内置版本的Mac OS(X),这似乎是问题的核心.
为了解决这个问题,您必须安装一个自制的cURL库版本:
brew install curl --with-libssh2 --with-openssl
Run Code Online (Sandbox Code Playgroud)然后使用以下两个选项重新安装PHP :(
--with-homebrew-curl
--with-homebrew-openssl
包括您需要的任何选项)
brew install php56 --with-homebrew-curl --with-homebrew-openssl (--with-apache ...)
Run Code Online (Sandbox Code Playgroud)
或者用于PHP 7.2:
brew reinstall php72 --with-apache --with-homebrew-curl --with-homebrew-libxslt --with-homebrew-openssl --without-snmp
Run Code Online (Sandbox Code Playgroud)php -i | grep "SSL Version"
Run Code Online (Sandbox Code Playgroud)
应该给:
SSL Version => OpenSSL/1.0.2j
Run Code Online (Sandbox Code Playgroud)
注意:安装Homebrew cURL时会发出警告:
macOS已经提供了这个软件,并行安装另一个版本会造成各种麻烦.
我没有用这么长时间来验证任何现有/不存在的问题.
资料来源:https://www.farces.com/wikis/naked-server/php/php-openssl/
没有找到太多关于此错误的文档,该错误源于 Darwin SSL 错误 -9808 errSSLBadCert
。
如果使用 OpenSSL 而不是 Darwin SSL 编译 cURL,您可能会更幸运。
关于此错误的其他一些互联网搜索表明它可能无法读取您的钥匙串,但我对此不确定。
归档时间: |
|
查看次数: |
2535 次 |
最近记录: |