Getting Started with the AWS SDK for PHP

Articles & Tutorials>Amazon SQS>Getting Started with the AWS SDK for PHP
This guide shows you how to start building PHP applications on the Amazon Web Services platform with the AWS SDK for PHP.


Submitted By: Craig@AWS
AWS Products Used: Amazon CloudFront, Amazon EC2, Amazon S3, Amazon SQS, Amazon SimpleDB
Language(s): PHP
Created On: September 27, 2010 5:01 PM GMT
Last Updated: September 29, 2010 1:17 AM GMT

The AWS SDK for PHP helps you get started in minutes using a single, downloadable package. Using the PHP SDK, you can build solutions for many AWS products, such as Amazon Simple Storage Service (Amazon S3), Amazon Elastic Compute Cloud (Amazon EC2), and Amazon SimpleDB.

Get Set Up

To get set up, you must sign up for Amazon Web Services, get your AWS credentials, and set up your environment.

Sign Up for AWS Products

Before you can begin, you must sign up for each AWS product you want to use. The sample included in the SDK uses Amazon S3, so we'll use that product as an example here.

To sign up for a product
  1. Go to the home page for the product, for example

    Tip: Go to for a list of links to all our products.

  2. Click the sign-up button on the top right corner of the page.
  3. Follow the on-screen instructions. If you don't already have an AWS account, you are prompted to create one as part of the sign-up process.

AWS sends you a confirmation e-mail after the sign-up process is complete. You can view your current account activity or manage your account at any time, by going to and clicking the Account tab.

Get Your Credentials

In order to use the AWS SDK for PHP, you need your AWS Access Key ID and Secret Access Key.

To get your AWS Access Key ID and Secret Access Key
  1. Go to
  2. Click Account and then click Security Credentials.
    The Security Credentials page displays (you might be prompted to log in).
  3. Scroll down to Access Credentials and make sure the Access Keys tab is selected.
    The AWS Access Key ID appears in the Access Key column.
  4. To view the Secret Access Key, click Show.

Important! Your Secret Access Key is a secret, which only you and AWS should know. It is important to keep it confidential to protect your account. Store it securely in a safe place. Never include it in your requests to AWS, and never e-mail it to anyone. Do not share it outside your organization, even if an inquiry appears to come from AWS or No one who legitimately represents Amazon will ever ask you for your Secret Access Key.

Set Up Your Environment

Aside from a baseline understanding of object-oriented programming in PHP, there are a few minimum requirements to start using the AWS SDK for PHP. All the following requirements are common, and most extensions come installed with PHP 5.2 by default.

Minimum requirements are:

If you're not sure if your PHP installation supports these requirements, you can run the AWS SDK for PHP Compatibility Test. (Alternatively, you can check by either running phpinfo() in a browser or by running php -i from the command line.)

To install your PHP environment

  • To use Amazon CloudFront, you must have the OpenSSL PHP extension (which is different from any low-level OpenSSL libraries installed on your system) to sign private CloudFront URLs.
  • To use response caching with the following tools, you must install the associated extensions:
    • APCAPC PHP extension
    • XCacheXCache PHP extension
    • Memcache—Either the older Memcache PHP extension, or the newer Memcached PHP extension
    • SQLite—If PDO support isn't already enabled, install the SQLite 3 PHP extension and the PDO-SQLite driver

Install the SDK

There are a few ways you can grab the source for the AWS SDK for PHP, each option is described briefly here.

To install the AWS SDK for PHP

  • Choose your installation method from one of the following:
    • Install from downloadable file from
    • Install from Git. For more information on Git, explore Git for the lazy, or other Git references.
      git clone git:// AWSSDKforPHP
      cd ./AWSSDKforPHP
    • Install from Subversion
      svn co AWSSDKforPHP
      cd ./AWSSDKforPHP
    • Install from PEAR
      sudo pear channel-discover
      sudo pear install aws/sdk

Configure the SDK Security Credentials

There are two different ways to configure your credentials: one approach is geared for simplicity, whereas the other is geared for flexibility. The simple approach is preferred for all installation approaches except PEAR. This flexible approach is preferred if you are installing from PEAR; if you need it, find a copy of the file on GitHub.

To add your AWS credentials the simple way (non-PEAR)

  1. Navigate to the file in the SDK directory, and rename it to
  2. Open for editing. There are instructions in this file for what each configuration value, should be and where you can find it.
  3. When the SDK is loaded, it will first look for in the same directory as sdk.class.php. You are now ready to run the sample!

Caution! Be sure to back up your file when upgrading to avoid having to re-enter your credentials.

To add your AWS credentials the flexible way (PEAR)

  1. Create a new configuration file at ~/.aws/sdk/
    You can either download and copy the contents of a file, or grabdirectly from the above GitHub link.
  2. Open for editing. There are instructions in this file for what each configuration value, and where you can find it.
  3. Enter echo getenv('HOME'); to verify that PHP can access the HOME environment variable .
  4. If the previous command doesn't t return the correct file path to your user directory, configure it with putenv('HOME=<your-user-path>');.

Run the Sample

The AWS SDK for PHP contains sample code demonstrating how to use the AWS SDK for PHP with Amazon S3. The sample creates an Amazon S3 bucket, uploads a number of files from a test-files/ directory in to the bucket, then displays a URL for each file.

Important! Before you run the sample you must configure the SDK with your AWS security credentials. For more information, see Configure the SDK Security Credentials.

To run the Amazon S3 Sample

  • Run the cli-s3_get_urls_for_uploads.php file located in the samples/ folder of the SDK installation directory.

Where Do I Go from Here?

For more information about the AWS SDK for PHP, including a complete list of supported AWS products, go to

SDK Reference Documentation

The SDK reference documentation includes the ability to browse and search across all code included with the SDK. It provides thorough documentation, usage examples, and even the ability to browse method source. You can find it at

Tutorials and Screencasts

Learn more about using the AWS SDK for PHP from our list of articles, tutorials, and screencasts:

©2017, Amazon Web Services, Inc. or its affiliates. All rights reserved.