S3-php5-curl on AWS EC2 instance - requested domain name does not match the server's certificate

amazon-ec2, amazon-s3, apache, linux, php

Solution

Try using AWS SDK for PHP 1.5.5 and make sure that you specify your region and set `path_style` to true. For me I'm in Singapore so my code will be:

 $s3 = new AmazonS3();
 $s3->set_region(AmazonS3::REGION_APAC_SE1);
 $s3->path_style = true;

This seems to work for me.

Hope it helps!

Cheers, Ardy

Problem

I am using s3-php5-curl to access my AWS S3 bucket. The `getBucket()` function works fine and retrieves a result when I host the PHP app myself but when I put the exact same code into a AWS EC2 instance (default AIM - Linux, Apache, PHP), I get the following error: `Warning: S3::getBucket(): [51] Unable to communicate securely with peer: requested domain name does not match the server's certificate. In /var/www/html/s3-php5-curl/S3.php on line 136 Warning: Invalid argument supplied for foreach() in /var/www/html/index.php on line 15` I can't make sense of it. What does it mean and how can I resolve it? EDIT: I did mark this as answered but I was wrong. I have linked to what the underlying problem seems to be irrespective of whether you use the Amazon SDK or the php5-curl library. There seems to be a general problem affecting EC2 users in some regions who try to programmatically access their S3 buckets relating to SSL certification where the bucket name includes a full-stop (aka period). It has been documented but lays unresolved here.

Original source