Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awsdocs
GitHub Repository: awsdocs/amazon-s3-developer-guide
Path: blob/master/code_examples/php_examples/S3examples/s3-bucket-website-configuration.php
4084 views
1
<?php
2
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
// SPDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/LICENSE-SAMPLECODE )
4
5
require 'vendor/autoload.php';
6
7
use Aws\S3\S3Client;
8
9
$bucket = '*** Your Bucket Name ***';
10
11
$s3 = new S3Client([
12
'version' => 'latest',
13
'region' => 'us-east-1'
14
]);
15
16
17
// Add the website configuration.
18
$s3->putBucketWebsite([
19
'Bucket' => $bucket,
20
'WebsiteConfiguration' => [
21
'IndexDocument' => ['Suffix' => 'index.html'],
22
'ErrorDocument' => ['Key' => 'error.html']
23
]
24
]);
25
26
// Retrieve the website configuration.
27
$result = $s3->getBucketWebsite([
28
'Bucket' => $bucket
29
]);
30
echo $result->getPath('IndexDocument/Suffix');
31
32
// Delete the website configuration.
33
$s3->deleteBucketWebsite([
34
'Bucket' => $bucket
35
]);
36
37