I have a working account on Amazon S3. I have used it together with my shared hosting and it has worked well. I have now setup an Amazon EC2 instance with Amazon Linux (a similar CentOS / Redhat Linux) and installed apache and php with
sudo yum install -y httpd24 php56
and added www group etc from this page. Everything else expect MySQL. http://ift.tt/1aE3oJu
Installed AWS SDK to EC2 from composer and it worked great.
I can run simple PHP scripts on EC2 without problems, e.g
<?php phpinfo(); ?>
But this example code is not working on my EC2.
require 'vendor/autoload.php';
use Aws\Common\Aws;
use Aws\S3\S3Client;
$aws = S3Client::factory(array(
'key' => 'CORRECT KEY, USING THE SAME ON MY SHARED HOSTING',
'secret' => 'CORRECT SECRET, USING THE SAME ON MY SHARED HOSTING',
// 'region' => 'us-east-1',
));
$bucket = 'CORRECT BUCKET';
$objects = $aws->getIterator('ListObjects', array('Bucket' => $bucket));
echo "Keys retrieved!\n";
foreach ($objects as $object) {
echo $object['Key'] . "\n";
}
This code works fine on my shared hosting but not on EC2. I have tested to list all buckets and other simple code that works fine on my shared hosting but not on EC2.
I can see that the SDK is included on my page on EC2 with this.
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "$filename\n";
}
Have I missed something on EC2? Why is the same code working on my shared hosting but not on EC2 to the same Amazon S3 account/bucket. No error messages on the page or something else that indicates that something is wrong.
Aucun commentaire:
Enregistrer un commentaire