How to enable HTTPS stream wrappers

Tamppox picture Tamppox · Feb 21, 2010 · Viewed 61.8k times · Source

I installed php5 on my windows system and tried to execute the following script with a command-line console:

<?php
// load in credentials
$creds = parse_ini_file('/etc/aws.conf');

// Define query string keys/values
$params = array(
    'Action' => 'DescribeAvailabilityZones',
    'AWSAccessKeyId' => $creds['access_key'],
    'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
    'Version' => '2008-05-05',
    'ZoneName.0' => 'us-east-1a',
    'ZoneName.1' => 'us-east-1b',
    'ZoneName.2' => 'us-east-1c',
    'SignatureVersion' => 2,
    'SignatureMethod' => 'HmacSHA256'
);

// See docs
// http://tr.im/jbjd
uksort($params, 'strnatcmp');
$qstr = '';
foreach ($params as $key => $val) {
    $qstr .= "&{$key}=".rawurlencode($val);
}
$qstr = substr($qstr, 1);

// Signature Version 2
$str = "GET\n"
     . "ec2.amazonaws.com\n"
     . "/\n"
     . $qstr;

// Generate base64-encoded RFC 2104-compliant HMAC-SHA256
// signature with Secret Key using PHP 5's native 
// hash_hmac function.
$params['Signature'] = base64_encode(
    hash_hmac('sha256', $str, $creds['secret_key'], true)
);

// simple GET request to EC2 Query API with regular URL 
// encoded query string
$req = 'https://ec2.amazonaws.com/?' . http_build_query(
    $params
);
$result = file_get_contents($req);

// do something with the XML response
echo $result;

But it says that it's unable to find the wrapper "https" and asks if I forget to enable it when I configured PHP.

What is the problem and how to settle it?

Answer

Drew picture Drew · Mar 10, 2010

1: Check which wrappers are installed.

<?php var_dump(stream_get_wrappers()); ?>

2: If you dont see "https" on the list, add to/uncomment from php.ini

extension=php_openssl.dll

Restart your server*, and your done.

*if server fails to restart go download php_openssl.dll from someplace and stick it in your extensions directory defined in the php.ini file, restart server, say a few hell mary's and pray.