RustFS: Connecting PHP to RustFS

This documentation is part of the Quick start guide guide. You can view the complete guide here: How to begin using RustFS for S3-compatible object storage.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use RustFS Object Storage platform, engineered for reliability and speed. Key benefits include:

  • Unlimited data transfers with no hidden fees.
  • Simple, predictable, and transparent pricing.
  • A custom domain name secured with HTTPS (for example, https://object-storage.your-company.com).
  • A web console and admin API that you can restrict from the internet with a single click.
  • Smooth, one-click updates with no manual intervention required.
  • High performance and security on private, dedicated infrastructure.
  • Available in both 🇪🇺 Europe and 🇺🇸 USA regions.

Optimise your workflow and reduce setup time: you can deploy Stackhero's RustFS Object Storage hosting in just 5 minutes.

First, install the AWS SDK for PHP:

composer require aws/aws-sdk-php

The example below connects to RustFS from PHP using the AWS SDK:

<?php

require 'vendor/autoload.php';

$s3 = new Aws\S3\S3Client([
  'version' => 'latest',
  'region'  => 'us-east-1',
  'endpoint' => 'https://<XXXXXX>.stackhero-network.com',
  'use_path_style_endpoint' => true,
  'credentials' => [
    'key'    => '<ROOT_ACCESS_KEY>',
    'secret' => '<ROOT_SECRET_KEY>'
  ],
]);

// Create a bucket
$s3->createBucket([ 'Bucket' => 'testbucket' ]);

// Upload an object
$s3->putObject([
  'Bucket' => 'testbucket',
  'Key'    => 'testkey',
  'Body'   => 'Hello from RustFS!'
]);

// Download the object and print its content
$retrieve = $s3->getObject([
  'Bucket' => 'testbucket',
  'Key'    => 'testkey'
]);

echo $retrieve['Body'];