我正在尝试使用php Amazon SDK
从运行AppServ 2.5.10
(包括Apache 2.2.8
,php 5.2.6
,mysql 5.0.51b
和phpMyAdmin 2.10.3
(的(本地主机(Windows 8机器连接Amazon的S3文件。
为了与命名空间功能兼容Amazon SDK's
我通过下载其压缩文件并将其解压缩来将 php 替换为版本 5.3.28
。
我的 php 代码可以正常工作S3
可以访问Amazon EC2
文件,但它在我的 Windows 本地主机中失败了。
但是,当我运行php srcipt以读取Windows本地主机中的Amazon S3
存储桶文件时,出现SSL错误,如下所示:
致命错误:未捕获的异常"Guzzle''Http''Exception''CurlException" 带有消息"[curl] 60:SSL 证书问题:无法获取本地 颁发者证书 [网址] https://images-st.s3.amazonaws.com/us/123977_sale_red_car.png' in C:''AppServ''www''ecity''vendor''guzzle''guzzle''src''Guzzle''Http''Curl''CurlMulti.php:342 堆栈跟踪:
#0 C:''AppServ''www''ecity''vendor''guzzle''guzzle''src''Guzzle''Http''Curl''CurlMulti.php(283(: Guzzle''Http''Curl''CurlMulti->isCurlException(Object(Guzzle''Http''Message''Request(, 对象(guzzle''http''curl''curlHandle(, array(
#1 C:''AppServ''www''ecity''vendor''guzzle''guzzle''src''Guzzle''Http''Curl''CurlMulti.php(248(: Guzzle''Http''Curl''CurlMulti->processResponse(Object(Guzzle''Http''Message''Request(, 对象(guzzle''http''curl''curlHandle(, array(
#2 C:''AppServ''www''ecity''vendor''guzzle''guzzle''src''Guzzle''Http''Curl''CurlMulti.php(231(: Guzzle''Http''Curl''CurlMulti->processMessages((
#3 C:''AppServ''www''ecity''vendor''guzzle''guzzle''src''Guzzle''Http''Curl''CurlMulti.php(215(: Guzzle''Http''Curl''CurlMulti->executeHandles((
#4 C:''AppServ''www''ecity''ven in C:''AppServ''www''ecity''vendor''aws''aws-sdk-php''src''Aws''Common''Client''AbstractClient.php 在第 288 行
我从 http://curl.haxx.se/ca/cacert.pem 下载证书并在 php 中定义它.ini如下所示:
curl.cainfo = "C:'AppServ'cacert.pem"
但我仍然得到同样的错误。似乎 php 不遵守 php.ini
中定义的curl.cainfo
。
根据localhost/phpinfo.php
,我的php版本是5.3.28
的。
我还检查了cainfo
参数是否正确,C:'AppServ'cacert.pem
使用
echo ini_get( "curl.cainfo" ) ;
在 PHP 脚本中。
高于 5.3
的 PHP 版本应支持 php.ini
中的curl.cainfo
。
在Windows的命令行中,我检查了curl行为,它似乎工作正常。
C:'Users'Jordan>curl https://s3-us-west-2.amazonaws.com/images-st/aaa.txt
curl: (60) SSL certificate problem: unable to get local issuer certificate
......
C:'Users'Jordan>curl --cacert C:'AppServ'cacert.crt https://s3-us-west-2.amazonaws.com/images-st/aaa.txt
This is aaa.txt file.
Stored in Amazon S3 bucket.
是因为我在 Windows 中使用了 Apache,它与我从 VC9 x86 线程安全 (2014-Jun-11 01:09:56( zip 版本下载 http://windows.php.net/download/php 5.3.28
zip 文件不匹配。
在我的 apache 的 httpd-ssl.conf 文件中,即使我在 Windows 8 中从本地主机使用,我也具有以下设置。
<VirtualHost _default_:443>
DocumentRoot "C:/AppServ/www"
ServerName localhost:443
ServerAdmin webmaster@localhost.com
ErrorLog "C:/AppServ/Apache2.2/logs/error.log"
TransferLog "C:/AppServ/Apache2.2/logs/access.log"
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "C:/AppServ/Apache2.2/conf/mydomain.cert"
SSLCertificateKeyFile "C:/AppServ/Apache2.2/conf/mydomain.key"
<FilesMatch "'.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/Apache2.2/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" '
nokeepalive ssl-unclean-shutdown '
downgrade-1.0 force-response-1.0
CustomLog "C:/AppServ/Apache2.2/logs/ssl_request.log" '
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x '"%r'" %b"
</VirtualHost>
现在我想知道问题是什么以及如何连接到Amazon S3
存储桶文件和RDS
数据库而不产生这些curl
无法从我的 Windows 8 本地主机获取本地颁发者证书问题。
有什么建议吗?
正如 Jeremy Lindblom 在评论中提到的,AWS 开发工具包 v2 的解决方案是在实例化开发工具包时设置 ssl.certificate_authority
选项:
$aws = Aws'Common'Aws::factory(array(
'region' => 'us-west-2',
'ssl.certificate_authority' => '/path/to/updated/cacert.pem'
));
http://docs.aws.amazon.com/aws-sdk-php/guide/latest/faq.html#what-do-i-do-about-a-curl-ssl-certificate-error
我要补充一点,这在 AWS 开发工具包 v3 中已更改,这是新方法:
$client = new DynamoDbClient([
'region' => 'us-west-2',
'version' => 'latest',
'http' => [
'verify' => '/path/to/my/cert.pem'
]
]);
http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html#verify
对于使用WampServer的用户,请打开php.ini
文件,然后向下滚动到底部并添加以下内容:
curl.cainfo = "C:'wamp'bin'php'php7.2.3'cacert.pem"
确保您正在使用的当前 php 版本的文件夹中有cacert.pem
文件。就我而言,我将其放在php7.2.3
文件夹中。
我遇到了同样的错误 如果你想使用http,那么你可以使用下面的解决方案:
Error executing "PutObject" on "https://s3-ap-southeast-2.amazonaws.com/mybucketname/TestBanner1_e1d8d74e41"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
我已经通过使用http方法解决了它,这是不安全的,使用安全的方式输入_curl.cainfo = "/path/to/file.cacert.pem"_在php.ini文件中:
解决方案:
'options' => [
'scheme' => 'http',
],
完整的示例代码:
// ...
's3bucket' => [
'class' => 'frostealth'yii2'aws's3'Storage::className(),
'region' => 'ap-southeast-2',
'credentials' => [ // Aws'Credentials'CredentialsInterface|array|callable
'key' => 'JGUTEHCDE.............OSHS',
'secret' => 'SJEUC-----------jzy1-----rrT',
],
'bucket' => 'yours3bucket',
//'cdnHostname' => 'http://example.cloudfront.net',
'defaultAcl' => 'frostealth'yii2'aws's3'Storage::ACL_PUBLIC_READ,
'debug' => false, // bool|array
'options' => [
'scheme' => 'http',
],
],
// ...
$s3 = new S3Client
([
'version' => 'latest',
'scheme' =>'http',
'region' => $this->config->item('s3_region'),
'credentials' => [
'key' => $this->config->item('s3_access_key'),
'secret' => $this->config->item('s3_secret_key')
],
]);
如果您的协议是 Http,请将方案添加到 http
我遇到了同样的问题,但经过研究,我找到了适用于 AWS S3 存储桶的 Laravel 原生解决方案。
第 1 步:转到config/filesystems.php
第 2 步:在"s3">数组中添加'scheme' => 'http'
,如下所示:
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false,
'scheme' => 'http'
],
就是这样。现在,您可以运行应用并对其进行测试。
在实时服务器上移动 Web 应用后,如果 Web 应用通过 https 协议运行,则需要删除此属性