php - Ubuntu php 7.2 Laravel cURL 错误 60:SSL 证书问题:无法获取本地颁发者证书,请参阅 http://curl.haxx.se
问题描述
我在 Ubuntu 上有 Laravel 和 PHP 7.2。我想从网站下载比特币价格:
https://btczexplorer.blockhub.info/ext/getbalance/t1ZYiG4R4n5gTgUKZRgVpKPzG5FYQXpEqga
在服务器上我收到错误:
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
我在互联网上发现我必须安装证书。所以我做了:
root@server-1456254-1:/etc/ssl/certs# sudo wget http://curl.haxx.se/ca/cacert.pem
root@server-1456254-1:/etc/php/7.2/apache2# nano php.ini
in php.ini:
openssl.cafile=/etc/ssl/certs/cacert.pem
root@server-1456254-1:/etc/php/7.2/apache2# /etc/init.d/apache2 restart
但错误仍然发生。怎么了?
-- 在 Laravel 的 php 文件中调用了上面 btczexplorer 的 url:
public function blockNotify($blockId)
{
try {
$response = Rate::getAddressApiBalance('t1ZYiG4R4n5gTgUKZRgVpKPzG5FYQXpEqga');
return $response;
}catch (\Exception $e) {
return $e->getMessage() . ' stack trace: ' . $e->getTraceAsString();
}
return "end";
和评分文件:
public static function getAddressApiBalance($address)
{
try {
$uri = "https://btczexplorer.blockhub.info/ext/getbalance/" . $address;
$response = Http::get($uri);
return $response;
} catch (InvalidArgumentException $exception){
return 3;
Log::error($exception);
} catch (Exception $e) {
return $e->getMessage();
Log::error($e);
}
return 0;
}
在网站上我的证书有错误。
为什么我使用本地或 CA?我在互联网上找到了这个解决方案。
使用 file_get_contents 我们有同样的错误:
结果相同:file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:1416F086:SSL 例程:tls_process_server_certificate:证书验证失败堆栈跟踪:#0 [内部函数]:Illuminate\Foundation\Bootstrap\HandleExceptions-> handleError(2, 'file_get_conten...', '/var/www/html/b...', 43, Array) #1 /var/www/html/bitpay/app/Http/Controllers/BlockApiController.php( 43): file_get_contents(' https://btczexp...') #2 [内部函数]: App\Http\Controllers\BlockApiController->blockNotify('00000051507a8ce...') #3 /var/www/html/bitpay/vendor/laravel/framework/src/Illuminate /Routing/Controller.php(54): call_user_func_array(Array, Array) #4 /var/www/html/bitpay/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\控制器->callAction('blockNotify', Array) #5
var_dump(openssl_get_cert_locations())
也许命令显示会有所帮助:
array(8) { ["default_cert_file"]=> string(21) "/usr/lib/ssl/cert.pem" ["default_cert_file_env"]=> string(13) "SSL_CERT_FILE" ["default_cert_dir"]=> string(18) "/usr/lib/ssl/certs" ["default_cert_dir_env"]=> string(12) "SSL_CERT_DIR" ["default_private_dir"]=> string(20) "/usr/lib/ssl/private" ["default_default_cert_area"]=> string(12) "/usr/lib/ssl" ["ini_cafile"]=> string(25) "/etc/ssl/certs/cacert.pem" ["ini_capath"]=> string(0) "" }
所以我改变了证书的 php.ini 路径:openssl.cafile=/usr/lib/ssl/certs/cacert.pem
但没有结果
现在我已将代码更改为纯 guzzle 客户端:
$url = 'https://btczexplorer.blockhub.info/ext/getbalance/t1ZYiG4R4n5gTgUKZRgVpKPzG5FYQXpEqga';
$http = new Client(['verify' => '/usr/lib/ssl/certs/cacert.pem']);
$options = [];
$response = $http->request('GET', $url, $options);
我得到同样的错误:
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) stack trace: #0 /var/www/html/bitpay/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(149): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 /var/www/html/bitpay/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(102): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2
解决方案
我认为找到证书是一个卷曲问题。
所以尝试在 php.ini 中更改这个选项(它需要一个绝对路径):
curl.cainfo = “/etc/ssl/certs/cacert.pem”
推荐阅读
- html - 如何使用 css nth child 使我的最后一个导航链接具有不同的颜色
- angular-material - 是否可以为对象设置多个 mat-select 下拉值?
- apache-spark - Pyspark:由于窗口功能上的 OutOfMemory 而失败
- ios - 成功 IAP 后验证 Apple 收据时 original_transaction_id 未出现
- go - 如何“去安装”到模块目录中的bin?
- android - AES/GCM/NoPadding 解密需要 TAG 加密时如何找到 Tag
- r-markdown - 有没有办法重新格式化 Rmarkdown 文档中的所有代码块?
- c++ - c ++使用原始指针创建循环依赖对象
- node.js - 在 Google Cloud 上访问 process.env.BASE_URL - Node.Js/Express
- python - 使用 SQLAlchemy 从 INSERT 语句中获取 MSSQL 自动生成的 ID