PHP-SSL证书错误:无法获取本地颁发者证书
我在Windows7上运行PHP版本5.6.3作为XAMPP的一部分 当我尝试使用Mandrill API时,出现以下错误: 未捕获异常“Mandrill_HttpError”,消息为“API调用消息/发送模板失败:SSL证书问题:无法获取本地颁发者证书” 我已经尝试了StackOverflow上读到的所有内容,包括在php.ini文件中添加以下内容:PHP-SSL证书错误:无法获取本地颁发者证书,php,ssl,curl,xampp,mandrill,Php,Ssl,Curl,Xampp,Mandrill,我在Windows7上运行PHP版本5.6.3作为XAMPP的一部分 当我尝试使用Mandrill API时,出现以下错误: 未捕获异常“Mandrill_HttpError”,消息为“API调用消息/发送模板失败:SSL证书问题:无法获取本地颁发者证书” 我已经尝试了StackOverflow上读到的所有内容,包括在php.ini文件中添加以下内容: curl.cainfo = "C:\xampp\php\cacert.pem" 当然,我们可以从以下位置下载cacert.pem文件 但在所有
curl.cainfo = "C:\xampp\php\cacert.pem"
当然,我们可以从以下位置下载cacert.pem文件
但在所有这些之后,重新启动了XAMPP和Apache服务器,但仍然得到相同的错误
我真的不知道还能尝试什么
有人能告诉我还有什么可以尝试的吗
免责声明:此代码使您的服务器不安全
在Mandrill.php文件的第65行之后,我也遇到了同样的问题,它说$this->ch=curl_init()
添加以下两行:
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
这解决了我的问题,还使用localhost发送了电子邮件,但我建议不要在live版本上使用它。在live server上,代码应该可以在没有此代码的情况下运行。当您查看页面时,您会注意到一个大字部分,名为:
已删除RSA-1024
阅读它,然后下载包含“RSA-1024”证书的证书版本。
这些将与Mandrill一起使用
禁用SSL是一个坏主意。终于实现了这一点
c:\wamp\
目录(如果您使用的是wamp64位,那么它是c:\wamp64\
)mod_ssl
,在php.ini中启用php_openssl.dll
(通过在开头删除;
来取消注释)。但是要小心,我的问题是我有两个php.ini
文件,我需要在这两个文件中都这样做。一个是您从WAMP任务栏图标获得的,另一个是在C:\WAMP\bin\php\php5.5.12\
php.ini
文件中将这些行添加到您的证书中:
curl.cainfo="C:/wamp/cacert.pem"
openssl.cafile="C:/wamp/cacert.pem"
谢谢@Mladen Janjetovic 你的建议在安装了AMPS的mac中对我有效 已复制: 至:
/Applications/AMPPS/extra/etc/openssl/certs/cacert.pem
并使用该路径更新了php.ini
,并重新启动了Apache:
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo="/Applications/AMPPS/extra/etc/openssl/certs/cacert.pem"
openssl.cafile="/Applications/AMPPS/extra/etc/openssl/certs/cacert.pem"
并且在windows AMPS安装中应用了相同的设置,并且在其中也非常有效
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo="C:/Ampps/php/extras/ssl/cacert.pem"
openssl.cafile="C:/Ampps/php/extras/ssl/cacert.pem"
:
wamp也一样
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo="C:/wamp/bin/php/php5.6.16/extras/ssl/cacert.pem"
openssl.cafile="C:/wamp/bin/php/php5.6.16/extras/ssl/cacert.pem"
如果您正在寻找使用SAN for localhost生成新的SSL证书,则在
Centos 7/Vagrant/Chrome Browser
上的步骤对我有效。上述步骤虽然有用,但在Windows 8上对我无效。我不知道两者之间的关系,但下面的步骤奏效了。基本上是cacert.pem文件中的更改。希望这对别人有帮助
- 从此处下载cacert.pem文件:
- 将文件保存在PHP安装文件夹中。(例如:如果使用xampp–将其保存在c:\Installation\u Dir\xampp\php\cacert.pem中)李>
- 打开php.ini文件并添加以下行:
- curl.cainfo=“C:\Installation\u Dir\xampp\php\cacert.pem” openssl.cafile=“C:\Installation\u Dir\xampp\php\cacert.pem”
- 重新启动Apache服务器,这应该可以修复它(只需停止并启动 根据需要提供服务)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
在AppVeyor中构建应用程序时,我也遇到了同样的问题
- 下载到
c:\php
- 启用openssl
echo extension=php\u openssl.dll>>c:\php\php.ini
- 找到证书
echo curl.cainfo=c:\php\cacert.pem>>c:\php\php.ini
希望它能帮助别人。如果您无法访问php.ini,添加此代码(在
$ch=curl_init();
行之后)对我有效:
$certificate_location = "C:\Program Files (x86)\EasyPHP-Devserver-16.1\ca-bundle.crt"; // modify this line accordingly (may need to be absolute)
curl_setopt($ch, CURLOPT_CAINFO, $certificate_location);
curl_setopt($ch, CURLOPT_CAPATH, $certificate_location);
然后,您只需将其下载并保存到您在
$certificate\u location
中指定的位置,详细说明服务器部署的上述答案
$hostname = gethostname();
if($hostname=="mydevpc")
{
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
在部署时,应在不影响服务器的情况下为开发环境执行此操作。对于guzzle,您可以尝试以下方法:
$client = new Client(env('API_HOST'));
$client->setSslVerification(false);
在guzzle/guzzle 3上测试。*我对这个问题有非常简单的解决方案。您可以在没有任何证书文件的情况下执行此操作 继续Laravel根文件夹->Vender->guzzlehttp->guzzle->src 打开Client.php 查找$defaults数组。看起来像这样
$defaults = [
'allow_redirects' => RedirectMiddleware::$defaultSettings,
'http_errors' => true,
'decode_content' => true,
'verify' => true,
'cookies' => false
];
现在的主要工作是更改验证键的值
'verify' => false,
因此,在此之后,它将不会检查CURL请求的SSL证书。。。这个解决方案对我来说是可行的。经过多次研究,我找到了这个解决方案……我试过了,它很有效
打开
改变这个
$conf[CURLOPT_SSL_VERIFYHOST] = 2;
`enter code here`$conf[CURLOPT_SSL_VERIFYPEER] = true;
对此
$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = FALSE;
我得到的错误如下:
failed loading cafile stream: `C:\xamppPhp\apache\bin\curl-ca-bundle.crt`
我使用的是windows机器。因此,我遵循以下步骤
1. I have downloaded .pem file from " https://curl.haxx.se/docs/caextract.html "
2. Then I kept the downloaded file inside "C:/xamppPhp/apache/bin/" folder and renamed the same downloaded file to "curl-ca-bundle.crt".
3. I restarted XAMPP and cleared the cache.
4. It's done.
希望它可以帮助某人我在本地系统中遇到了这样的问题,但在实时服务器中没有。我在本页上还提到了另一个解决方案,但它在localhost中不起作用。因此,请找到一个新的解决方案,它在localhost WAMP服务器中起作用
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL =>$url,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER=> true,
));
curl_setopt($curl, CURLOPT_CAINFO, "f:/wamp/bin/cacert.pem"); // <------
curl_setopt($curl, CURLOPT_CAPATH, "f:/wamp/bin/cacert.pem"); // <------
$response = json_decode(curl_exec($curl),true);
$err = curl_error($curl);
curl_close($curl);
cURL错误#:SSL证书问题:无法获取本地颁发者
证书
有时系统无法在驱动器中找到您的cacert.pem。所以
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL =>$url,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER=> true,
));
curl_setopt($curl, CURLOPT_CAINFO, "f:/wamp/bin/cacert.pem"); // <------
curl_setopt($curl, CURLOPT_CAPATH, "f:/wamp/bin/cacert.pem"); // <------
$response = json_decode(curl_exec($curl),true);
$err = curl_error($curl);
curl_close($curl);
wget --no-check-certificate -c https://www.geotrust.com/resources/root_certificates/certificates/GeoTrust_Global_CA.pem \
&& mkdir /usr/local/share/ca-certificates/extra \
&& mv GeoTrust_Global_CA.pem /usr/local/share/ca-certificates/extra/GeoTrust_Global_CA.crt \
&& update-ca-certificates