AWS SDK for PHP 2
Getting Started Guide
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Did this page help you?  Yes | No |  Tell us about it...

Installing the SDK

This section describes the different ways that your can install the AWS SDK for PHP 2.

Installing via Composer

Using Composer is the recommended way to install the AWS SDK for PHP 2. Composer is dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project. In order to use the AWS SDK for PHP 2 through Composer, you must do the following:

  1. Add "aws/aws-sdk-php" as a dependency in your project's composer.json file.

    {
      "require": {
          "aws/aws-sdk-php": "*"
      }
    }
    

    Consider tightening your dependencies to a known version when deploying mission critical applications (e.g., 2.0.*).

  2. Download and install Composer.

    curl -s "http://getcomposer.org/installer" | php
    
  3. Install your dependencies.

    php composer.phar install
    
  4. Require Composer's autoloader.

    Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process.

    require '/path/to/sdk/vendor/autoload.php';
    

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at getcomposer.org.

Installing via Phar

Each release of the AWS SDK for PHP ships with a pre-packaged phar file containing all of the classes and dependencies you need to run the SDK. Additionally, the phar file automatically registers a class autoloader for the AWS SDK for PHP and all of its dependencies when included. Bundled with the phar file are the following required and suggested libraries:

Installing via PEAR

PEAR, which stands for PHP Extension and Application Repository, is a framework and distribution system for reusable PHP components. It is the PHP equivalent of other package management solutions like Yum that install packages system-wide.

PEAR packages are easy to install, and are available in your PHP environment path so that they are accessible to any PHP project. PEAR packages are not specific to your project, but rather to the machine they're installed on.

From the command-line, you can install the SDK with PEAR as follows:

pear channel-discover pear.amazonwebservices.com
pear install aws/sdk

Note: You may need to use sudo for the above commands.

Once the SDK has been installed via PEAR, you can load the phar into your project with:

require 'AWSSDKforPHP/aws.phar';