![](/img/trans.png)
[英]cURL error 60: SSL certificate problem: self signed certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
[英]Ubuntu php 7.2 Laravel cURL error 60: SSL certificate problem: unable to get local issuer certificate see http://curl.haxx.se
我在 Ubuntu 上安裝了帶有 PHP 7.2 的 Laravel。 我想從網站下載比特幣價格:
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 operation failed with code 1. OpenSSL 錯誤消息:error:1416F086:SSLroutines:tls_process_server_certificate:certificate verify failed stack trace: #0 [internal function]: 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\\Controller->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”
我嘗試了上面接受的答案,更新了評論中提到的 curl 和 openssl 設置,但兩者都不起作用。 與提問者類似,我從http://curl.haxx.se/ca/cacert.pem (按照此處的說明)下載了證書,但我將證書放在 /usr/local/share/ca-certificates/ 中。
就我而言,問題不僅限於 Laravel,而是與作曲家本身有關。 命令composer diagnose
顯示了可怕的錯誤“cURL 錯誤 60:SSL 證書問題:無法獲得本地頒發者證書”。
我更新了所有服務器包sudo apt-get update && sudo apt-get upgrade
現在作曲家正在工作(錯誤消失了)。 我刪除了之前設置的 curl 和 openssl 值,然后進行了測試,發現 composer 仍然有效。 所以就我而言,設置 php 值根本不是解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.