How to Disable SSL Verification in Laravel HTTP Requests
When building integrations with third-party APIs, you sometimes encounter cURL errors like SSL certificate problem: unable to get local issuer certificate. This specific error, often seen as cURL error 60, indicates that the underlying library responsible for making network requests cannot validate the server's SSL certificate chain against a trusted root store.
In the context of Laravel, this usually happens during development when you are running the application behind a local web server (like Apache or PHP's built-in server) without a valid TLS certificate, or if your php.ini configuration lacks the necessary CA bundle. However, before attempting to disable verification, it is crucial to understand that bypassing SSL checks is a security risk and should generally be avoided in production environments where the API endpoint is properly secured.
The error log you are seeing points directly to the verify option within the cURL handle used by Laravel's Http facade. When this option defaults to true, Laravel attempts to verify the server's certificate against the system's trusted CA certificates. If your local environment does not have these certificates configured correctly, or if you are testing with a self-signed certificate on the API side, the request fails.
To resolve this specifically for your local development environment where SSL is not running on your Apache server, you need to tell the Http facade to skip certificate verification. In Laravel 9 and later, the Illuminate\Http\Client facade provides a clean way to do this using the withOptions method.
Here is how you can modify the requestPayment method in your controller:
public function requestPayment(Request $request)
{
$paystack_key = config('app.paystack_key');
$url = "https://api.paystack.co/transaction/initialize";
$email = $request->user('distributors')->email;
$fields = [
"email" => $email,
"amount" => 50 * 100,
"channels" => ["card"],
"callback_url" => "d"
];
// Disable SSL verification for development only
$response = Http::post($url, $fields)
->withHeaders([
'Authorization' => 'Bearer ' . $paystack_key,
'Cache-Control' => 'no-cache',
])
->withOptions([
'verify' => false
]);
return $response;
}
The critical line here is ->withOptions(['verify' => false]). This tells the underlying cURL handle to skip certificate verification. This allows the request to proceed even if the local server lacks a valid SSL certificate or if the API returns a self-signed certificate during your testing phase.
However, there are significant trade-offs you must consider. Disabling SSL verification disables the protection against Man-in-the-Middle (MitM) attacks. If you were running this code on a public machine without disabling verify, an attacker on the same network could intercept and read your traffic. Since you mentioned that production will provide proper SSL, this solution is strictly for local debugging.
If you prefer not to disable verification globally or want to handle certificate issues more robustly, another approach is to ensure your PHP environment has the correct CA bundle configured. You can check if the openssl.cafile or openssl.capath options are set in your php.ini file. In many modern Linux distributions, these paths are auto-detected, but on older setups or specific containers, you might need to point them to a path containing the root certificates (like /etc/ssl/certs/ca-certificates.crt).
One common mistake developers make is assuming that setting verify => false fixes the issue in production. It does not. In a production environment, your application should always verify SSL certificates. If you encounter this error in production, it usually means the API provider's certificate has expired or there is a mismatch in the domain name. You should investigate the root cause rather than bypassing the check.
For more complex scenarios involving custom CA bundles or specific proxy settings, Laravel also supports passing additional cURL options via withOptions. Always ensure that any code disabling SSL verification includes clear comments indicating its intended scope (e.g., "Development only") to prevent accidental deployment to production environments.