0
0

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

Last updated at Posted at 2023-12-27

発生環境

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

発生経緯

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に記述を追加

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

結果

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

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を用いて検証をスキップしただけ。
あんまりお勧めできないが信頼できるホストかつ開発環境ならこれの方が楽

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0