21

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'
);

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?

1
  • 8
    Maybe you forgot to enable https when you configured PHP? Commented Feb 21, 2010 at 13:13

4 Answers 4

45

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.

Sign up to request clarification or add additional context in comments.

6 Comments

btw: i detest curl, stick with the fopen's like file_get_contents.... fsockopen is like the daddy.
Regarding @Costa comment, beware often the Command Line php is picking up a different php.ini file, that's caught me out before.
Yup, that's why I mentioned it. :) If you need to check what streams are available to the command line, that's the command to use (I was in the situation you describe).
dont forget to uncomment extension_dir in `php.ini'
I found it as ;extension=openssl (remove the semicolon to uncomment it.)
|
10

The file_get_contents line, at the end of your script, is trying to send an HTTPS request -- see the URL in $req, which starts by 'https://ec2...'.

For this to be possible, PHP needs a "wrapper" to send HTTPS requests -- which doesn't seem to be installed on your system ; which means you cannot send HTTPS requests using the fopen familly of functions.

For more informations about stream wrappers, if you are curious, you can take a look at List of Supported Protocols/Wrappers, and, in your case, HTTP and HTTPS.

You'll either have to install the HTTPs wrapper -- on Windows, I have no idea how to do that, unfortunately...


Or you'll have to use something else that file_get_contents to send your HTTPS request -- I would use the functions provided by the curl extension (Here, too, not sure it will work "out of the box", though :-( ).

For an example, you can take a look at what's proposed on the manual page of curl_exec :

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

Note you'll probably have to set a couple more options, using curl_setopt -- you should go through that page : there are a lot of useful options ;-)


As a sidenote, you are using this line at the beginning of your script :

$creds = parse_ini_file('/etc/aws.conf');

The path /etc/aws.conf feels strange, as you said you are using a Windows system : this looks like the kind of path one would use on an UNIX/Linux system.

1 Comment

I believe he needs to install SSL support to get that on Windows
4

Open php.ini. Find this line:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; ...
;extension=ext/php_oci8.dll
extension=ext/php_openssl.dll         ; <---- you want this
;extension=ext/php_pdo_firebird.dll
; ...

you want to uncomment the extension=ext/php_openssl.dll line. Make sure there is a pho_openssl.dll file in the ext/ directory, relative to your php.ini (or maybe more importantly to the extension_dir variable in the ini).

Comments

2

Simple. I had this error and gave me such headaches. Enable (uncomment the line extension=php_openssl.dll) in your php.ini file. This will solve the issue.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.