Twilio PHP - SSL certificate: self signed certificate in certificate chain
I'm struggling with this error when trying to send a message via Twilio using their PHP library:
Fatal error: Uncaught exception Services_Twilio_TinyHttpException with message SSL certificate problem: self signed certificate in certificate chain thrown in F:\path\to\site\twilio-php\Services\Twilio\TinyHttp.php on line 119
I'm using wamp on windows 7.
I have of course found all of the other posts about certificate errors. From what I can see, usually updating or adding the cacert.pem
file fixes the issue. However, even after doing this i'm still getting the same error.
Just as a sanity check here is exactly what i've done:
- Downloaded the latest certificates from here: http://curl.haxx.se/ca/cacert.pem.
- Placed this file in the following location
c:/wamp/certs/cacert.pem
- Updated php.ini as follows:
curl.cainfo = c:/wamp/certs/cacert.pem
- Restarted all wamp services including apache
And i'm still getting the same error. I have verified that I am editing the correct php.ini using phpinfo()
. I'm at a loss as to why it's still complaining.
Is there any way to verify 100% that my cacert.pem
file is being found and read? I've checked phpinfo()
and there is no mention of it in there. Should it say somewhere which, if any cacert.pem
it's using?
Thanks!
Solution 1:
I had the exact same issue
Follow these steps:
Download the following file - cacert.pem
Then download the following file - thawte_Premium_Server_CA.pem
Open the second file in a text editor and copy its contents into the first file (cacert.pem
at the bottom/end).
Save cacert.pem
and add the following lines to your php.ini
:
[curl]
curl.cainfo=c:/xampp/php/cacert.pem
Obviously change the directory to the one where your pem is located. Restart the php local server (xampp/wamp). Then it will work flawlessly.
thanks.
Solution 2:
Edit TinyHttp.php
and add CURLOPT_SSL_VERIFYPEER => FALSE,
at $opts array
Solution 3:
I'm not using Twilio, but I am on Windows and was having the exact problems described in the OP. I resolved this by downloading the ca-bundle.crt
file from this page and pointing my php.ini to it:
http://curl.haxx.se/docs/caextract.html
Solution 4:
Instead of hacking tiny_http.php, you can add your own cURL options by calling Twilio's CurlClient constructor with your chosen options, like:
$client = new \Twilio\Rest\Client($accountSid, $authToken);
$curlOptions = [ CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false];
$client->setHttpClient(new CurlClient($curlOptions));
try {
$call = $client->calls->create($from_phone, $phone_number, $callback_url);
print 'Call queued with Twilio';
} catch (\Exception $ex) {
print 'Twilio error: ' . $ex->getMessage();
}