Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Managing Websites with the AWS SDK for PHP

The following tasks guide you through using the PHP classes to manage website configuration of your bucket. For more information about the Amazon S3 website feature, see Hosting Websites on Amazon S3.

Managing Bucket Website Configuration

1

Create an instance of the AmazonS3 class by providing your AWS credentials.

2

To configure a bucket as a website, execute the AmazonS3.create_website_config method. You need to provide the bucket name and the website configuration information including the index document and the error document names. If you don't provide these document names, this method adds the index.html and error.html default names to the website configuration. You must verify that these documents are present in the bucket.

To retrieve existing bucket website configuration, execute the AmazonS3.get_website_config method by passing the bucket name as a parameter.

To delete website configuration from a bucket, execute the AmazonS3.delete_website_config method by passing the bucket name as a parameter. If you remove the website configuration, the bucket is no longer accessible from the website endpoints.


The following PHP code sample demonstrates the preceding tasks.

<?php
require_once '../aws-sdk-for-php/sdk.class.php';
header('Content-Type: text/plain; charset=utf-8');

$bucket = '*** Provide bucket name ***'; 
$indexDocument = '*** Provide index document name ****'; 
$errorDocument = '*** Provide error document name ***';

// Instantiate the class
$s3 = new AmazonS3();

// 1) Add website config. to bucket.
$response = $s3->create_website_config($bucket, 
                                       array(
                                         'indexDocument' => $indexDocument,
                                         'errorDocument' => $errorDocument));

// 2) Retrieve website configuration.
$response = $s3->get_website_config($bucket);
header('Content-Type: text/plain; charset=utf-8');

// 3) Delete website configuration.
$response = $s3->delete_website_config($bucket);

Example

The following PHP code example first adds a website configuration to the specified bucket. The create_website_config method explicitly provides the index document and error document names. The sample also retrieves the website configuration and prints the response. For more information about the Amazon S3 website feature, see Hosting Websites on Amazon S3. For instructions on how to create and test a working sample, see Using the AWS SDK for PHP.

<?php
require_once '../aws-sdk-for-php/sdk.class.php';
header('Content-Type: text/plain; charset=utf-8');

$bucket = '*** Provide bucket name ***'; 
$indexDocument = '*** Provide index document name ****'; 
$errorDocument = '*** Provide error document name ***';

// Instantiate the class
$s3 = new AmazonS3();

// 1) Add website config. to bucket.
$response = $s3->create_website_config($bucket, 
                                       array(
                                         'indexDocument' => $indexDocument,
                                         'errorDocument' => $errorDocument));
// Success?
 var_dump($response->isOK());

// 2) Retrieve website configuration.
$response = $s3->get_website_config($bucket);
header('Content-Type: text/plain; charset=utf-8');
print_r($response);

// 3) Delete website configuration.
$response = $s3->delete_website_config($bucket);
var_dump($response->isOK());