Using PHP with Eucalyptus

qyjohn edited this page Mar 12, 2013 · 8 revisions

If you are developing your own Web based tool for Eucalyptus in PHP, you may want to interact with Eucalyptus using an SDK.


To use these tools you'll need:

  • A Linux system running a LAMP stack
  • A running Eucalyptus cloud, with user credentials (This guide was tested on Eucalyptus 3.1.2)
  • git revision control tool installed


The AWS SDK for PHP ( provides a great tool kit for interacting with the Amazon Web Services APIs, including EC2 and S3, which we can re-use in Eucalyptus.

The SDK has not been fully validated on Eucalyptus and is not supported by Eucalyptus Systems but it does seem to work without modification, your mileage may vary.


  1. Download SDK and ensure you are using version 1.5.3 - this is the last SDK before introduction of the HMAC4 signing code, which Eucalyptus does not yet support:

    git clone /var/www/aws-sdk-for-php
    cd /var/www/aws-sdk-for-php
    git checkout 1.5.3
  2. Create a test page to make sure the SDK works (/var/www/aws-sdk-for-php/eucalyptus-example.php):

    Replace 'your-access-key', 'your-secret-access-key' and '', with your Eucalyptus Access Key, Secret Key and DNS name found within your Eucalyptus 'eucarc' credentials.

    require_once 'sdk.class.php';
    $ec2 = new AmazonEC2(array(
        'key' => 'your-access-key',
        'secret' => 'your-secret-access-key',
    $ec2->set_hostname("", 8773);
    $ec2->disable_ssl(); // If you need to disable SSL
    $response = $ec2->describe_images();
    if ($response->isOK()) {
        // `body` is a SimpleXMLElement
        foreach ($response->body->imagesSet->item as $item) {
            $image_id = (string) $item->imageId;
            print_r($image_id . "\n");
    } else {
        // error--dump the whole request
  3. Run the PHP test page via the command-line:

    php /var/www/aws-sdk-for-php/eucalyptus-example.php
  4. Adapt the code based on examples provided on the AWS site, to use it within your own website code.

Example: Simple page to launch an instance

This page provides a simple form to launch and instance and uses a few different API queries :


PHP-AWS ( is a collection of small PHP scripts that use PHP-Curl to query the Eucalyptus API.

  1. Download the scripts:

    git clone /var/www/php-aws
    cd /var/www/php-aws
  2. Modify class.ec2.php to point to your Eucalyptus server.


    var $_server     = "";


    var $_server     = "";
  3. Create a test page to ensure the scripts are working (/var/www/php-aws/euca-test.php)

    Replace 'your-access-key', 'your-secret-access-key' and '_put-an-emi-id-here', with your credentials and a Eucalyptus Machine Image to run.

        // ec2 sdk code
        // Credentials for ec2 function
        $ec2    = new EC2('your-access-key', 'your-secret-access-key');
        $run = $ec2->runInstances('put-an-emi-id-here', 1, 1, 'key_name');
  4. Run the test script via the command line:

    php /var/www/php-aws/euca-test.php
  5. Some more code samples to describe images and instances, as well as terminate instances:

    // list all images
    $images = $ec2->getImages();
    foreach ($images as $image_id=>$image)
        $image_location = $image["location"];
        print_r($image_id . ” ” . $image_location . “\n”);
    // start an instance
    $ec2->runInstances(“emi-XXXXXXXX”, 1, 1, “key_name”);
    // list all instances
    $instances = $ec2->getInstances();
    foreach ($instances as $instance_id=>$instance)
        $image_id = $instance["imageId"];
        $state = $instance["state"];
        $dns = $instance["dns"];
        print_r($instance_id . ” ” . $image_id . ” ” . $state . ” ” . $dns . “\n”);
    // terminate an instance

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.