# How to use the AWS SDK for PHP with Stook?

You can connect PHP applications to **Medianova Stook Object Storage** using the **AWS SDK for PHP**. This allows you to create buckets, upload files, and retrieve objects from Stook directly in your PHP projects.

***

### Prerequisites

* PHP installed on your system
* AWS SDK for PHP
* Medianova Stook credentials:
  * **Access Key**
  * **Secret Key**
  * **Endpoint**

***

### Installation

Follow [AWS SDK for PHP installation guide](https://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html):

***

### Example Code

Create a PHP file and configure your Stook connection:

```php
<?php
require 'aws/aws-autoloader.php';

$s3 = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-east-1',
    'endpoint' => 'Enter server info',
    'use_path_style_endpoint' => true,
    'credentials' => [
        'key'    => 'Enter Access Key',
        'secret' => 'Enter Secret Key',
    ],
   'http'    => [
       'verify' => false
    ]
]);

try {
    $s3->createBucket(array('Bucket' => 'testbucket'));
}
catch (Exception $e){
    echo "There is a bucket with that name!<br>";
}

// Sending a PutObject request and getting the results
$insert = $s3->putObject([
    'Bucket' => 'testbucket',
    'Key'    => 'testkey',
    'Body'   => 'Hello world'
]);

// Download the contents of the object
$retrive = $s3->getObject([
    'Bucket' => 'testbucket',
    'Key'    => 'testkey',
    'SaveAs' => 'testkey_local'
]);

//Index the body to the result object
echo $retrive['Body'];
```

*Example PHP code for connecting to Stook, creating a bucket, uploading and retrieving objects*

***

### Troubleshooting / FAQ

* **Error:** “There is a bucket with that name!”
  * **Solution:** Use a unique bucket name.
* **Error:** Connection issues
  * **Solution:** Ensure endpoint URL is correct and matches Stook.
* **Error:** Permission denied
  * **Solution:** Validate Access Key and Secret Key.

***

### References

* [AWS SDK for PHP Installation Guide](https://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html)
* [Medianova Stook Storage User Guide for AWS CLI](https://docs.medianova.com/stook-storage-user-guide-for-aws-cli/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clients.medianova.com/products/object-storage-stook/integration-and-usage-guides/how-to-use-the-aws-sdk-for-php-with-stook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
