我很难通过媒体神殿中的aws-php-sdk设置使用亚马逊网络服务S3的凭据。
我仍然收到错误:Cannot read credentials from /.aws/credentials
我尝试按照指南通过https://docs.aws.amazon.com/cli/latest/userguide/awscli-install-linux.html安装AWS CLI。然后,我使用以下代码通过https://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html#configure-cli设置凭据
..。但我仍然会遇到这个错误。
然后,我与Media Temple support进行了交谈,后者在根目录中创建了.aws/credentials文件,但随后错误消息更改为:
Warning: is_readable(): open_basedir restriction in effect. File(/.aws/credentials) is not within the allowed path(s)
MT建议我不要更改basedir设置。他们还建议我在可能的情况下简单地更改凭据的读取位置。
有人在MT上成功使用了AWS凭证吗?
发布于 2018-09-15 00:22:21
试图通过SSH使用AWS CLI来做到这一点,就像在Media Temple上用头撞砖墙一样。
然后,我尝试通过环境变量设置凭据,但这是行不通的。
然后,我想到了将凭证文件放在PHP可以访问的目录中。但是,我必须设置aws-php-sdk查找它的位置。我在一些文档中找到了该环境变量,并尝试通过php的setenv()函数设置该变量。没有骰子。
然后我在aws-php-sdk中搜索我看到的初始错误,回溯到我可以找到设置凭据文件位置的位置。事实证明文档是错误的,正确的环境变量名是HOME。
最后,所有需要做的就是在使用亚马逊网络服务之前设置HOME。这很容易,但理应比这简单100倍。大致是这样的:
// Set environment variable for credentials location
putenv('HOME=../');
// Set bucket name
$this->bucket = $bucket;
// Create an S3Client
$this->s3Client = new Aws\S3\S3Client([
'profile' => $this->profile,
'version' => $this->version,
'region' => $this->region
]);https://stackoverflow.com/questions/52334245
复制相似问题