
fix “SSL certificate problem: unable to get local issuer certificate” error
When you execute PHP CURL calls to HTTPS URLs, you might get the following error:
SSL certificate problem: unable to get local issuer certificate
This means that the root certificates on the system are invalid.
You have 3 different ways to proceed:
- Maintain SSL enabled – change php.ini:
- Downloaded cacert.pem from http://curl.haxx.se/ca/cacert.pem
- Copy cacert.pem to ‘/usr/local/openssl-0.9.8/certs/cacert.pem’ // Or whatever version of openssl / zend you have.
- Modify CURL configuration on your php.ini file:
- Below [curl] add => cainfo = ‘/usr/local/openssl-0.9.8/certs/cacert.pem’
- Restart PHP and check if CURL can read from HTTPS URL.
- Maintain SSL enabled – do not change php.ini:
- Use the following code to use the credentials you got on the previous step:
1234$ch = curl_init();$certificate_location = '/usr/local/openssl-0.9.8/certs/cacert.pem';curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $certificate_location);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $certificate_location);
- Use the following code to use the credentials you got on the previous step:
- Disable SSL – NOT RECOMMENDED:
-
123$ch = curl_init();curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-