PHP -SSL证书错误:无法获得本地发行人证书

发布于 2025-01-28 03:07:32 字数 535 浏览 6 评论 0 原文

作为Windows 7上XAMPP的一部分,我正在运行PHP版本5.6.3。

当我尝试使用Mandrill API时,我会收到以下错误:

未被发现的异常“ mandrill_httperror”,带有消息'api呼叫的消息/发送 - 板呼叫失败:SSL证书问题:无法获取本地发行者证书'

我已经尝试了我在Stackoverflow上阅读的所有内容,包括将以下内容添加到php.ini文件中

curl.cainfo = "C:\xampp\php\cacert.pem"

:从 http://curl.haxx.se/caextract/caextract..html ,

但是毕竟,重新启动XAMPP和Apache服务器,但仍会遇到相同的错误。

我真的不知道还要尝试什么。

谁能建议我还能尝试什么?

I'm running PHP Version 5.6.3 as part of XAMPP on Windows 7.

When I try to use the Mandrill API, I'm getting the following error:

Uncaught exception 'Mandrill_HttpError' with message 'API call to messages/send-template failed: SSL certificate problem: unable to get local issuer certificate'

I already tried everything I read on StackOverflow, including adding the following to the php.ini file:

curl.cainfo = "C:\xampp\php\cacert.pem"

And ofcourse downloaded to that location the cacert.pem file from http://curl.haxx.se/docs/caextract.html

but after all that, restarted XAMPP and Apache server but still getting the same error.

I really don't know what else to try.

Can anyone advise on what else can I try?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

小耗子 2025-02-04 03:07:32

终于让这个工作了!

  1. 下载证书捆绑包

  2. 将其放在某个地方。就我而言,那是 c:\ wamp \ 目录(如果您使用的是Wamp 64位,则是 c:\ wamp64 \ )。

  3. eNable mod_ssl 在apache中, php_openssl.dll in php.ini in php.ini (通过删除; 在intem> in 在开始)。但是要小心,我的问题是我有两个 php.ini 文件,我需要在两个文件中执行此操作。一个是您从WAMP任务栏图标中获得的一个,另一个是在我的情况下,在 c:\ wamp \ bin \ php \ php \ php \ php5.5.12 \

  4. 中两个 php.ini 文件中的证书:

      curl.cainfo =“ c:/wamp/cacert.pem”
    openssl.cafile =“ c:/wamp/cacert.pem”
     
  5. 重新启动WAMP服务。

Finally got this to work!

  1. Download the certificate bundle.

  2. Put it somewhere. In my case, that was c:\wamp\ directory (if you are using Wamp 64 bit then it's c:\wamp64\).

  3. Enable mod_ssl in Apache and php_openssl.dll in php.ini (uncomment them by removing ; at the beginning). But be careful, my problem was that I had two php.ini files and I need to do this in both of them. One is the one you get from your WAMP taskbar icon, and another one is, in my case, in C:\wamp\bin\php\php5.5.12\

  4. Add these lines to your cert in both php.ini files:

    curl.cainfo="C:/wamp/cacert.pem"
    openssl.cafile="C:/wamp/cacert.pem"
    
  5. Restart Wamp services.

错爱 2025-02-04 03:07:32

编辑的注释 :禁用SSL验证具有安全含义。无需验证SSL/HTTPS连接的真实性,恶意攻击者可以模仿恶意的攻击者值得信赖的端点(例如github或其他远程git主机),您将容易受到中间攻击

在使用此问题之前,请确保您完全了解安全问题。

我在第65行之后的mandrill.php文件中遇到了同样的问题,其中说$ this-> ch = curl_init();

添加以下两行:

curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);

这解决了我的问题,还使用Localhost发送了电子邮件,但我建议不要在实时版本中使用它。在您的实时服务器上,代码应在没有此代码的情况下工作。

Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.

Be sure you fully understand the security issues before using this as a solution.

I had the same problem in Mandrill.php file after line number 65 where it says $this->ch = curl_init();

Add following two lines:

curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);

This solved my problem and also sent email using localhost but I suggest to NOT use it on live version live. On your live server the code should work without this code.

酒废 2025-02-04 03:07:32

感谢@Mladen Janjetovic,

您的建议在Mac中安装了Mac,安装了AMPP。

复制: http://curl.haxx.se/ca/ca/cacert。 pem

to: /applications/ampps/extra/etc/openssl/certs/certs/cacert.pem

和更新 php.ini with with那条路径和重新启动的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 Ampps安装中应用相同的设置,并且它也可以很好地工作。

[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证书“ rel =“ noreferrer”>这篇文章在 centos 7 / vagrant / chrome浏览器< / code>上为我工作。

Thanks @Mladen Janjetovic,

Your suggestion worked for me in mac with ampps installed.

Copied: http://curl.haxx.se/ca/cacert.pem

To: /Applications/AMPPS/extra/etc/openssl/certs/cacert.pem

And updated php.ini with that path and restarted 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"

And applied same setting in windows AMPPS installation and it worked perfectly in it too.

[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"

:
Same for 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"

If you are looking for generating new SSL certificate using SAN for localhost, steps on this post worked for me on Centos 7 / Vagrant / Chrome Browser.

梦罢 2025-02-04 03:07:32

当您查看 http://curl.haxx.se/docs/docs/docs/caextract/caextract页面,您会在大写字母中注意到:

RSA-1024删除

,然后下载包含“ RSA-1024”证书的证书的版本。

这些将与Mandrill一起使用。

禁用SSL是一个坏主意。

When you view the http://curl.haxx.se/docs/caextract.html page, you will notice in big letters a section called:

RSA-1024 removed

Read it, then download the version of the certificates that includes the 'RSA-1024' certificates.
https://github.com/bagder/ca-bundle/blob/e9175fec5d0c4d42de24ed6d84a06d504d5e5a09/ca-bundle.crt

Those will work with Mandrill.

Disabling SSL is a bad idea.

谁的年少不轻狂 2025-02-04 03:07:32

以上步骤虽然很有帮助,但在Windows 8上对我无效。我不知道共同关系,但是以下步骤奏效。基本上是cacert.pem文件的更改。希望这对某人有帮助。

The above steps, though helpful, didnt work for me on Windows 8. I don't know the co-relation, but the below steps worked. Basically a change in the cacert.pem file. Hope this helps someone.

  • Download cacert.pem file from here:
    http://curl.haxx.se/docs/caextract.html
  • Save the file in your PHP installation folder. (eg: If using xampp – save it in c:\Installation_Dir\xampp\php\cacert.pem).
  • Open your php.ini file and add these lines:
  • curl.cainfo=”C:\Installation_Dir\xampp\php\cacert.pem”
    openssl.cafile=”C:\Installation_Dir\xampp\php\cacert.pem”
  • Restart your Apache server and that should fix it (Simply stop and start the
    services as needed).
月棠 2025-02-04 03:07:32

注意 :禁用SSL验证具有安全性含义。而无需验证SSL/HTTPS连接的真实性,恶意攻击者可以模仿A值得信赖的端点(例如github或其他远程git主机),您将容易受到中间攻击

在使用此问题之前,请确保您完全了解安全问题。

我找到了没有任何必需认证的新解决方案,只能添加两个行代码。

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

Note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.

Be sure you fully understand the security issues before using this as a solution.

I found new Solution without any required certification to call curl only add two line code.

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
饮惑 2025-02-04 03:07:32

如果您无法访问 php.ini ,请添加此代码(在您的 $ ch = curl_init(); line之后)适用于我:

$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);

然后,您只会需要下载 $ CESTICT_LOCATION 中指定的位置。

If you don't have access to php.ini, adding this code (after your $ch = curl_init(); line) works for me:

$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);

Then, you will just need to download ca-bundle.crt and save it to location you specified in $certificate_location.

黎夕旧梦 2025-02-04 03:07:32

编辑的注释 :禁用SSL验证具有安全含义。无需验证SSL/HTTPS连接的真实性,恶意攻击者可以模仿恶意的攻击者值得信赖的端点(例如github或其他远程git主机),您将容易受到中间攻击

在使用此问题之前,请确保您完全了解安全问题。

我尝试了它

开放

vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php

并将其更改

 $conf[CURLOPT_SSL_VERIFYHOST] = 2;
 $conf[CURLOPT_SSL_VERIFYPEER] = true;

为此

$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = FALSE;

Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.

Be sure you fully understand the security issues before using this as a solution.

I tried this it works

open

vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php

and change this

 $conf[CURLOPT_SSL_VERIFYHOST] = 2;
 $conf[CURLOPT_SSL_VERIFYPEER] = true;

to this

$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = FALSE;
别挽留 2025-02-04 03:07:32

注意 :禁用SSL验证具有安全性含义。而无需验证SSL/HTTPS连接的真实性,恶意攻击者可以模仿A值得信赖的端点(例如github或其他远程git主机),您将容易受到中间攻击

在使用此问题之前,请确保您完全了解安全问题。

详细说明服务器部署的上述答案。

$hostname = gethostname();
if($hostname=="mydevpc")
{
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}

在部署时,应该为开发环境做一个问题,而不会损害服务器。

Note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.

Be sure you fully understand the security issues before using this as a solution.

elaborating on the above answers for server deployment.

$hostname = gethostname();
if($hostname=="mydevpc")
{
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}

should do the trick for development environment without compromising the server when deployed.

森林很绿却致人迷途 2025-02-04 03:07:32

解决方案修订。

我在我的本地系统中遇到了这样的问题,但在实时服务器中却没有。我之前在此页面上也提到了另一个解决方案,但这在 localhost 中都没有起作用。

因此,请遵循下面提到的步骤。

步骤1。 您可以从此处下载证书捆绑文件。 [https://curl.haxx.se/docs/caextract.html]

在我的身边,我的 wamp安装在f:\ wamp64 \目录(如果您使用的是Wamp 64位,则是f:\ wamp64)。

第2步

。强>在两个php.ini文件中将这些行添加到您的证书中:

 curl.cainfo="F:/wamp64/bin/ssl/cacert.pem"
 openssl.cafile="F:/wamp64/bin/ssl/cacert.pem"

重新启动WAMP服务。

Solution Revised.

I was facing a problem like this in my local system but not in the live server. I also mentioned another solution on this page before, but that was not working in localhost.so find a new solution for this, that is working in the localhost-WAMP Server.

So for this follow the steps mentioned below.

Step 1. You can download the certificate bundle file from here. [https://curl.haxx.se/docs/caextract.html]

On my side, my WAMP was installed on the F:\wamp64\ directory (if you are using Wamp 64-bit then it's F:\wamp64).

Step 2. To enable mod_ssl in Apache and php_openssl.dll in php.ini uncomment them by removing ;

Step 3. Add these lines to your cert in both php.ini files:

 curl.cainfo="F:/wamp64/bin/ssl/cacert.pem"
 openssl.cafile="F:/wamp64/bin/ssl/cacert.pem"

Restart Wamp services.

迷离° 2025-02-04 03:07:32

我对这个问题有适当的解决方案,让我们尝试理解此问题的根本原因。当无法使用系统证书存储中的根证书或远程SSL与链证书一起使用远程服务器SSL验证远程服务器SSL时,此问题就会出现。如果您的Linux系统具有root ssh访问权限,则可以尝试使用以下命令更新证书存储:

update-ca-cectificates

如果仍然't工作,然后您需要在证书存储中添加远程服务器的根和临时证书。您可以下载root和中级证书,然后将其添加到 /usr/local/local/share/ca-certificates 目录中,然后运行命令 update> update> update-ca--证书 。这应该解决问题。同样,对于Windows,您可以搜索如何添加根和中间证书。

您可以解决此问题的另一种方法是要求远程服务器团队将SSL证书添加为域根证书,中级证书和根证书。

I have a proper solution of this problem, lets try and understand the root cause of this issue. This issue comes when remote servers ssl cannot be verified using root certificates in your system's certificate store or remote ssl is not installed along with chain certificates. If you have a linux system with root ssh access, then in this case you can try updating your certificate store with below command:

update-ca-certificates

If still, it doesn't work then you need to add root and interim certificate of remote server in your cert store. You can download root and intermediate certs and add them in /usr/local/share/ca-certificates directory and then run command update-ca-certificates. This should do the trick. Similarly for windows you can search how to add root and intermediate cert.

The other way you can solve this problem is by asking remote server team to add ssl certificate as a bundle of domain root cert, intermediate cert and root cert.

我还不会笑 2025-02-04 03:07:32

在Amazon Linux(Centos / Red Hat等)上,我做了以下操作来解决此问题。首先复制从并将其放入/etc/pki/pki/ca-trust/source/aNchors/目录中。然后运行 update-ca-trust 命令。

这是一个从 https://serverfault.com/questions.com/questions.com /394815/how-to-update-curl-ca-bundle-on-redhat

curl https://curl.se/ca/ca/cacert.pem-o/o/etc/pki/ca-trust/源/锚/curl-cacert upded.pem&amp;&amp; 但是, update-ca-trust

由于curl被打破,因此实际上使用此命令下载cacert.pem文件。

wget -no-check-certificate http://curl.haxx.se/ca/cacert.pem

在运行 update> update> update> code> update-ca-trust 命令后,您可以重新启动Web服务器服务httpd restart for apache或 nginx restart for Nginx。

On Amazon Linux (CentOS / Red Hat etc) I did the following to fix this issue. First copy the cacert.pem downloaded from http://curl.haxx.se/ca/cacert.pem and put it in the /etc/pki/ca-trust/source/anchors/ directory. Then run the update-ca-trust command.

Here is a one liner taken from https://serverfault.com/questions/394815/how-to-update-curl-ca-bundle-on-redhat

curl https://curl.se/ca/cacert.pem -o /etc/pki/ca-trust/source/anchors/curl-cacert-updated.pem && update-ca-trust

However since curl was broken I actually used this command to download the cacert.pem file.

wget --no-check-certificate http://curl.haxx.se/ca/cacert.pem

After running the update-ca-trust command you can restart the web server service httpd restart for apache or service nginx restart for nginx.

泪是无色的血 2025-02-04 03:07:32

在Appveyor构建应用程序时,我遇到了同样的问题。

  • 下载 https://curl.haxx.se/ca/ca/cacert.pem 代码> c:\ php
  • 启用openssl echo扩展= p​​hp_openssl.dll&gt;&gt; C:\ php \ php.ini
  • 定位证书 echo curl.cainfo = c:\ php \ cacert.pem&gt;&gt;&gt; C:\ php \ php.ini

I had the same issue during building my app in AppVeyor.

  • Download https://curl.haxx.se/ca/cacert.pem to c:\php
  • Enable openssl echo extension=php_openssl.dll >> c:\php\php.ini
  • Locate certificateecho curl.cainfo=c:\php\cacert.pem >> c:\php\php.ini
烟酒忠诚 2025-02-04 03:07:32

可能发生此错误的另一个原因是,如果从系统中删除了CA捆绑包(并且不再在CA-CECETICATES中可用)。

目前,这是Geotrust Global CA的情况,该情况(除其他外)被用来签署用于推送通知的APN证书。

其他详细信息可以在此处的错误报告上找到:

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

Another reason this error can occur is if a CA bundle has been removed from your system (and is no longer available in ca-certificates).

This is currently the situation with the GeoTrust Global CA which (among other things) is used to sign Apple's certificate for APNS used for Push Notifications.

Additional details can be found on the bug report here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=962596

You can manually add the GeoTrust Global CA certificate on your machine as suggested by Carlos Alberto Lopez Perez:

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
薔薇婲 2025-02-04 03:07:32

如果上面的解决方案都不适用,则尝试将XAMPP安装更新为较新版本。

我正在使用PHP 5.5.11运行XAMPP,相同的确切代码不起作用,我以PHP 5.6.28升级到XAMPP,上面的解决方案工作。

此外,只有更新PHP也无法正常工作,似乎是该版本的XAMPP上的Apache和PHP设置的组合。

希望它对某人有帮助。

If none of the solutions above are working for you try updating your XAMPP installation to a newer version.

I was running XAMPP with php 5.5.11, the same exact code didn't work, I upgraded to XAMPP with php 5.6.28 and the solutions above worked.

Additionally only updating PHP didn't work either seems like a combination of apache and php settings on that version of XAMPP.

Hope it helps someone.

始终不够爱げ你 2025-02-04 03:07:32

我有错误的错误:

failed loading cafile stream: `C:\xamppPhp\apache\bin\curl-ca-bundle.crt`

我正在使用Windows Machine。所以我遵循以下步骤。

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.

希望它可以帮助某人

I got the error like :

failed loading cafile stream: `C:\xamppPhp\apache\bin\curl-ca-bundle.crt`

I am using windows machine. So I followed the below steps.

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.

Hope it may help someone

国际总奸 2025-02-04 03:07:32

只需在本地再加两行即可解决这个问题,这对我来说很好。

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

simply put two more line on local to solve the issue and this worked for me fine.

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
弱骨蛰伏 2025-02-04 03:07:32

curl_setopt($ ch,curlopt_ssl_verifypeer,false);

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);

蹲墙角沉默 2025-02-04 03:07:32

对于Guzzle,您可以尝试以下操作:

$client = new Client(env('API_HOST'));
$client->setSslVerification(false);

在Guzzle/Guzzle 3上进行测试3.**

for guzzle you can try this :

$client = new Client(env('API_HOST'));
$client->setSslVerification(false);

tested on guzzle/guzzle 3.*

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文