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.
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
- Go to the home page for the product, for example aws.amazon.com/s3/.
Tip: Go to aws.amazon.com/products for a list of links to all our products.
- Click the sign-up button on the top right corner of the page.
- 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 aws.amazon.com 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
- Go to http://aws.amazon.com/.
- Click Account and then click Security Credentials.
The Security Credentials page displays (you might be prompted to log in).
- 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.
- 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 Amazon.com. 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:
- PHP 5.2 or newer (5.2.14 or latest 5.3.x highly recommended).
Including SimpleXML, JSON, PCRE and SPL.
- cURL PHP extension (compiled with the OpenSSL libraries for HTTPS support).
- Ability to read from, and write to, the file system via file_get_contents() and file_put_contents().
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
- Use the links in the following table to get the appropriate installation for your environment:
Mac OS X
Amazon EC2 AMIs
- 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:
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 http://aws.amazon.com/sdkforphp
- Install from Git. For more information on Git, explore Git for the lazy, or other Git references.
git clone git://github.com/amazonwebservices/aws-sdk-for-php.git AWSSDKforPHP
- Install from Subversion
svn co http://svn.github.com/amazonwebservices/aws-sdk-for-php.git AWSSDKforPHP
- Install from PEAR
sudo pear channel-discover pear.amazonwebservices.com
sudo pear install aws/sdk
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
config-sample.inc.php file on GitHub.
To add your AWS credentials the simple way (non-PEAR)
- Navigate to the
config-sample.inc.phpfile in the SDK directory, and rename it to
config.inc.phpfor editing. There are instructions in this file for what each configuration value, should be and where you can find it.
- When the SDK is loaded, it will first look for
config.inc.phpin the same directory as
sdk.class.php. You are now ready to run the sample!
Caution! Be sure to back up your
config.inc.php file when upgrading to avoid having to re-enter your credentials.
To add your AWS credentials the flexible way (PEAR)
- Create a new configuration file at
You can either download and copy the contents of a config-sample.inc.php file, or grabdirectly from the above GitHub link.
config.inc.phpfor editing. There are instructions in this file for what each configuration value, and where you can find it.
echo getenv('HOME');to verify that PHP can access the HOME environment variable .
- If the previous command doesn't t return the correct file path to your user directory, configure it with
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.phpfile 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 aws.amazon.com/sdkforphp.
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 http://docs.amazonwebservices.com/AWSSDKforPHP/latest.
Tutorials and Screencasts
Learn more about using the AWS SDK for PHP from our list of articles, tutorials, and screencasts: