--- title: "AWS SDK for PHP v3 With Wasabi" slug: "how-do-i-use-aws-sdk-for-php-with-wasabi" updated: 2026-07-29T20:45:38Z published: 2026-07-29T20:45:38Z canonical: "docs.wasabi.com/how-do-i-use-aws-sdk-for-php-with-wasabi" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.wasabi.com/llms.txt > Use this file to discover all available pages before exploring further. # AWS SDK for PHP v3 With Wasabi [AWS SDK for PHP](https://aws.amazon.com/sdk-for-php/) v3 is validated for use with Wasabi. ## Using the PHP SDK Execute the following steps: 1. Install the [AWS SDK for PHP](https://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html). 2. (optional) Configure an additional [AWS CLI profile for Wasabi](https://docs.wasabi.com/docs/how-do-i-use-aws-cli-with-wasabi) account using the Wasabi keys. In this example, we set the profile name as "wasabi" in the "~/.aws/credentials" file. To help you use this SDK with Wasabi, we provided examples for both IAM and S3. - Setting the Credentials - Connecting to IAM and S3 Endpoints - Creating a User Using IAM - Creating a Bucket - Uploading an Object to the Bucket - Reading an Object From the Bucket - Deleting an Object From the Bucket Additional examples are available from the [AWS documentation](https://docs.aws.amazon.com/aws-sdk-php/v2/guide/). > [!NOTE] > The examples use Wasabi's us-east-1 storage region. For other Wasabi storage regions, use the appropriate [Wasabi service URL](https://docs.wasabi.com/docs/what-are-the-service-urls-for-wasabis-different-storage-regions). > [!NOTE] > Send all IAM requests to [iam.wasabisys.com](http://sts.wasabisys.com/) ## Setting the Credentials ```plaintext 'us-east-1',     'version' => 'latest',     'credentials' => $provider,     'endpoint' => 'https://s3.wasabisys.com', // Change this to your specific endpoint     'use_path_style_endpoint' => true ]); ?> ``` Or: ```plaintext [         'key' => '',         'secret' => ''     ],     'endpoint' => 'https://s3.wasabisys.com', // Change this to your specific endpoint     'region' => 'us-east-1', // Change this to your desired region     'version' => 'latest',     'use_path_style_endpoint' => true ]; ?> ``` ## Connecting to IAM and S3 Endpoints #### IAM ```plaintext $region,     'version' => 'latest',     'endpoint' => $endpoint,     'credentials' => [         'key' => '',         'secret' => '',     ], ]); ``` #### S3 ```plaintext $region,     'version' => 'latest',     'endpoint' => $endpoint,     'credentials' => [         'key' => '',         'secret' => '',     ], ]); $region, 'version' => 'latest', 'credentials' => [ 'key' => $accessKey, 'secret' => $secretKey, ], ]); // Desired IAM username to be created $iamUserName = 'your-iam-username'; // Replace with the desired IAM username try { // Attempt to create an IAM user with the specified username $result = $iamClient->createUser([ 'UserName' => $iamUserName, ]); // If successful, display a message echo "IAM user created: $iamUserName\n"; } catch (AwsException $exception) { // If an error occurs, display an error message and exit echo "Failed to create IAM user $iamUserName with error: " . $exception->getMessage() . "\n"; exit("Please fix error with IAM user creation before continuing.\n"); } ?> ``` ## Creating a Bucket ```plaintext $region, 'version' => 'latest', 'endpoint' => $endpoint, 'credentials' => [ 'key' => $accessKey, 'secret' => $secretKey, ], ]); try { // Attempt to create a bucket with the specified name $result = $s3client->createBucket([ 'Bucket' => $bucketName, ]); // If successful, display a message echo "Created bucket named: $bucketName\n"; } catch (AwsException $exception) { // If an error occurs, display an error message and exit echo "Failed to create bucket $bucketName with error: " . $exception->getMessage() . "\n"; // Print out the full exception for debugging // echo "Exception: " . $exception->getAwsRequestId() . "\n"; // echo "Exception: " . $exception->getAwsErrorType() . "\n"; exit("Please fix error with bucket creation before continuing.\n"); } ?> ``` ## Upload an Object to the Bucket ```plaintext $region, 'version' => 'latest', 'endpoint' => $endpoint, 'credentials' => [ 'key' => $accessKey, 'secret' => $secretKey, ], ]); // Replace with the local file path you want to upload $localFilePath =     DIR     . '/your-local-file.txt'; // Replace with the desired object key in the S3 bucket $s3Key = 'your-object-key.txt'; try { // Attempt to upload the local file to the S3 bucket $s3Client->putObject([ 'Bucket' => $bucketName, 'Key' => $s3Key, 'SourceFile' => $localFilePath, ]); // If successful, display a message echo "Uploaded $localFilePath to $bucketName/$s3Key.\n"; } catch (AwsException $exception) { // If an error occurs, display an error message and exit echo "Failed to upload $localFilePath with error: " . $exception->getMessage() . "\n"; exit("Please fix the error with file upload before continuing.\n"); } ?> ``` ## Reading an Object From the Bucket ```plaintext $region, 'version' => 'latest', 'endpoint' => $endpoint, 'credentials' => [ 'key' => $accessKey, 'secret' => $secretKey, ], ]); // Replace with the actual key of the object you want to read $objectKey = 'your-object-key'; try { // Attempt to get the content of the specified object in the S3 bucket $file = $s3Client->getObject([ 'Bucket' => $bucketName, 'Key' => $objectKey, ]); // Get the 'Body' of the file $body = $file['Body']; // Output the content of the object to the console echo $body->getContents(); // Optionally, you can read a specific number of bytes // echo $body->read(26);   } catch (AwsException $exception) { // If an error occurs, display an error message and exit echo "Failed to read $objectKey from $bucketName with error: " . $exception->getMessage() . "\n"; exit("Please fix error with object reading before continuing.\n"); } ?> ``` ## Deleting an Object From the Bucket ```plaintext $region, 'version' => 'latest', 'endpoint' => $endpoint, 'credentials' => [ 'key' => $accessKey, 'secret' => $secretKey, ], ]); // Replace with the actual file name you want to download and delete $fileName = 'your-file-name.txt'; try { // Attempt to get the content of the specified file in the S3 bucket $file = $s3Client->getObject([ 'Bucket' => $bucketName, 'Key' => $fileName, ]); // Get the 'Body' of the file $body = $file->get('Body'); $body->rewind(); // Output the content of the file to the console echo "Downloaded the file and it begins with: {$body->read(26)}.\n"; // Delete the file from S3 $s3Client->deleteObject([ 'Bucket' => $bucketName, 'Key' => $fileName, ]); echo "Deleted $fileName from $bucketName.\n"; } catch (AwsException $exception) { // If an error occurs, display an error message and exit echo "Failed to download or delete $fileName from $bucketName with error: " . $exception->getMessage() . "\n"; exit("Please fix the error before continuing.\n"); } ?> ```