LaravelでAPIを叩いた時に[cURL error 60: SSL certificate problem]が出てきた時の対処法(本番環境非推奨)

最終更新日: 2025-05-29T04:29:31.751Z • 5分で読めます

発生環境

  • MAMP
  • PHP 8.3
  • Laravel 10.35
  • MySQL
  • Apache

発生経緯

php namespace App\Http\Controllers; 
use Illuminate\Support\Facades\Http; 
public function syncPost(Request $request){          
    $fetched = Http::get("https://example.com/api/");       
    return response()->json(["response" => 200]); 
}  

Laravelを用いて上記のようなコードでAPIを叩いたところ、以下のようなエラーが出た。

 cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://example.com/api/ {"userId":1,"exception":"[object] (GuzzleHttp\\Exception\\RequestException(code: 0): 
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://example.com/api/ at /Users/projectdir/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:211) [stacktrace] 

検索してみた結果 以下のような手順が出てきた

  • 証明書をダウンロード
  • php.iniに記述を追加

う---ん...めんどくさい...

結果

本番環境は非推奨だが、開発環境でパパッとやるなら以下のように書き換えればよさそう

php namespace App\Http\Controllers; 
use Illuminate\Support\Facades\Http;  
public function syncPost(Request $request){
   $fetched = Http::withOptions(['debug' => true, 'verifiy_host' => false])->get("http://example.com/api/");     
    return response()->json(["response" => 200]);
}

やったことは単純でwithOptionsを用いて検証をスキップしただけ。 あんまりお勧めできないが信頼できるホストかつ開発環境ならこれの方が楽

この記事をシェア:

Sophina

Sophina は、議事録や要件定義書からタスクを自動生成し、プロジェクト管理を効率化するAIプラットフォームです。