MinIO: Connecting PHP to MinIO

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

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use MinIO Object Storage solution that provides a host of benefits, including:

  • Unlimited transfers.
  • Simple, predictive, and transparent pricing.
  • Customisable domain name secured with HTTPS (for example, https://object-storage.your-company.com).
  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private and dedicated VM.
  • Available in 🇪🇺 Europe and 🇺🇸 USA.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's MinIO Object Storage hosting solution!

To connect PHP to MinIO, first install the AWS SDK for PHP package:

composer require aws/aws-sdk-php

The example below shows how to connect to MinIO from PHP using the AWS SDK:

<?php

// Include the SDK using the Composer autoloader
date_default_timezone_set('America/Los_Angeles');
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'    => 'YOUR_ACCESS_KEY',
    'secret' => 'YOUR_SECRET_KEY'
  ],
]);

// Send a PutObject request and obtain the result.
$insert = $s3->putObject([
  'Bucket' => 'testbucket',
  'Key'    => 'testkey',
  'Body'   => 'Hello from MinIO!'
]);

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

// Print the body of the retrieved result.
echo $retrieve['Body'];