

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Utilizzo di un bucket Amazon S3 come host Web statico con la versione 3 AWS SDK per PHP
<a name="s3-examples-static-web-host"></a>

È possibile ospitare un sito Web statico su Amazon S3. Per ulteriori informazioni, consulta [Hosting di un sito Web statico su Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html).

Gli esempi seguenti mostrano come:
+ Ottieni la configurazione del sito Web per un bucket utilizzando. [GetBucketWebsite](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#getbucketwebsite)
+ Imposta la configurazione del sito Web per un bucket utilizzando. [PutBucketWebsite](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putbucketwebsite)
+ Rimuovi la configurazione del sito Web da un bucket utilizzando. [DeleteBucketWebsite](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#deletebucketwebsite)

Tutto il codice di esempio per la AWS SDK per PHP versione 3 è [disponibile GitHub qui](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code).

## Credenziali
<a name="credentials-s3-examples-static-web-host"></a>

Prima di eseguire il codice di esempio, configura le tue AWS credenziali. Vedi [Credenziali per la AWS SDK per PHP versione 3](guide_credentials.md).

## Ottieni, imposta ed elimina la configurazione del sito Web per un bucket
<a name="get-set-and-delete-the-website-configuration-for-a-bucket"></a>

 **Importazioni** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\S3\S3Client;
```

 **Codice di esempio** 

```
$s3Client = new S3Client([
    'profile' => 'default',
    'region' => 'us-west-2',
    'version' => '2006-03-01'
]);

// Retrieving the Bucket Website Configuration
$bucket = 'amzn-s3-demo-bucket';
try {
    $resp = $s3Client->getBucketWebsite([
        'Bucket' => $bucket
    ]);
    echo "Succeed in retrieving website configuration for bucket: " . $bucket . "\n";
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}

// Setting a Bucket Website Configuration
$params = [
    'Bucket' => $bucket,
    'WebsiteConfiguration' => [
        'ErrorDocument' => [
            'Key' => 'foo',
        ],
        'IndexDocument' => [
            'Suffix' => 'bar',
        ],
    ]
];

try {
    $resp = $s3Client->putBucketWebsite($params);
    echo "Succeed in setting bucket website configuration.\n";
} catch (AwsException $e) {
    // Display error message
    echo $e->getMessage();
    echo "\n";
}

// Deleting a Bucket Website Configuration
try {
    $resp = $s3Client->deleteBucketWebsite([
        'Bucket' => $bucket
    ]);
    echo "Succeed in deleting policy for bucket: " . $bucket . "\n";
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```