MinIO
What is MinIO
MinIO is a high-performance, open-source object storage system designed to store unstructured data such as photos, videos, log files, backups, and container/VM images. It is fully compatible with the Amazon S3 API, making it easy to integrate with applications and tools that already support S3.
Install MinIO on Docker
To learn more or explore advanced container setup options, check out the official MinIO documentation here: https://min.io/docs/minio/container/index.html
Prerequisites
Before you start, ensure you have:
Docker installed on your system. If not, install Docker from the official Docker website
At least one available port (default: 9000 for API, 9001 for Console)
Step-by-Step Installation
Pull the MinIO Image:
Open a terminal or command prompt and run the following command to pull the MinIO Docker image:
docker pull minio/minio
. This downloads the official MinIO image from Docker Hub.
Run MinIO Container:
Standalone Mode:
Create a Data Directory:
mkdir C:\minio-data
Run this Docker command:
docker run -d --name minio_local -p 9000:9000 -p 9001:9001 -e "MINIO_ROOT_USER=minioadmin" -e "MINIO_ROOT_PASSWORD=minioadmin" -v C:\minio-data:/data minio/minio server /data --console-address ":9001"
Distributed Mode (Simulated on a Single Machine):
Create 4 Data Folders:
mkdir C:\minio-distributed\data1, C:\minio-distributed\data2, C:\minio-distributed\data3, C:\minio-distributed\data4
Run this Docker command:
docker run -p 9000:9000 -p 9001:9001 -v C:\minio-distributed\data1:/data1 -v C:\minio-distributed\data2:/data2 -v C:\minio-distributed\data3:/data3 -v C:\minio-distributed\data4:/data4 --name minio-distributed minio/minio server /data1 /data2 /data3 /data4 --console-address ":9001"
Verify Redis is Running:
Open a terminal or command prompt and run the following command to verify the MinIO container is running:
docker ps
. You should see a container named “minio_local” or “minio-distributed” running.
Access MinIO:
Web Console: Open http://localhost:9001
Port 9000 is API port
Login with the credentials:
Username: minioadmin
Password: minioadmin


MinIO Client
The MinIO Client (mc) is a command-line tool for managing MinIO and other S3-compatible storage services. It's essential for free users because it offers full access to manage buckets, files, and advanced features like policies and replication—capabilities not available in the basic web console.
Download MinIO Client
To interact with your MinIO server from the command line, please download the MinIO Client (mc) for Windows: https://dl.min.io/client/mc/release/windows-amd64/mc.exe
For detailed usage and commands, refer to the MinIO Client documentation: https://min.io/docs/minio/linux/reference/minio-mc.html
Running the following in the command prompt or powershell:
\path\to\mc.exe --help
This displays help information for the mc.exe executable.
Sample Use Case
MinIO File Management System (PHP)
index.php - Main Interface
File Upload: Handles multipart form uploads
Automatic Organization: Sorts files into folders by extension
File Listing: Displays all files in the bucket
Download Links: Provides secure download links
download.php - Secure Download Handler
Pre-signed URLs: Generates temporary, secure download links
Access Control: Ensures files remain private
Automatic Redirect: Seamlessly redirects users to the actual file
How Files Are Organized

Prerequisites
PHP Dependencies:
composer require aws/aws-sdk-php vlucas/phpdotenv
MinIO Server
MinIO server running (default: http://localhost:9000)
Admin credentials (default: minioadmin/minioadmin)
Created bucket (example: my-private-bucket)
Environment Configuration
Create a .env file in your project root:
MINIO_ENDPOINT=http://localhost:9000
MINIO_KEY=minioadmin
MINIO_SECRET=minioadmin
MINIO_BUCKET=my-private-bucket
MINIO_REGION=us-east-1
Configuration Parameters Explained
MINIO_KEY
Access key (username)
minioadmin
MINIO_SECRET
Secret key (password)
minioadmin
MINIO_BUCKET
Target bucket name
my-private-bucket
MINIO_REGION
AWS region format
us-east-1
Code Breakdown
index.php
Dependencies and Setup:
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Dotenv\Dotenv;
Uses the AWS SDK for PHP to interact with MinIO (S3-compatible)
Loads environment variables using DotEnv
MinIO Client Configuration:
$s3 = new S3Client([
'version' => 'latest',
'region' => $_ENV['MINIO_REGION'],
'endpoint' => $_ENV['MINIO_ENDPOINT'],
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $_ENV['MINIO_KEY'],
'secret' => $_ENV['MINIO_SECRET'],
],
]);
Key Configuration Details:
use_path_style_endpoint => true: Required for MinIO compatibility (uses endpoint/bucket/object instead of bucket.endpoint/object)
endpoint: Points to your MinIO server
credentials: Authentication using access key and secret
File Upload Logic:
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$file = $_FILES['file'];
$filename = $file['name'];
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
// Folder selection based on extension
switch ($extension) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
$folder = 'images/';
break;
// ... other cases
}
$key = $folder . $filename;
$s3->putObject([
'Bucket' => $bucket,
'Key' => $key,
'SourceFile' => $file['tmp_name'],
'ACL' => 'private'
]);
}
Upload Process:
Receives uploaded file via POST request
Extracts file extension
Determines appropriate folder based on extension
Uploads file to MinIO with putObject() method
Sets ACL to 'private' for security
File Listing:
$objects = $s3->listObjectsV2(['Bucket' => $bucket]);
Uses listObjectsV2() to retrieve all objects in the bucket
Displays files with download links
Simple User Interface:
<h2>Upload File</h2>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" required>
<button type="submit">Upload</button>
</form>
<h2>Files in Bucket</h2>
<ul>
<?php
if (!empty($objects['Contents'])) {
foreach ($objects['Contents'] as $obj) {
$key = urlencode($obj['Key']);
echo "<li>{$obj['Key']} - <a href='download.php?file={$key}'>Download</a></li>";
}
} else {
echo "<li>No files found.</li>";
}
?>
</ul>
download.php
Pre-signed URL Generation:
$cmd = $s3->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => $filename
]);
$request = $s3->createPresignedRequest($cmd, '+5 minutes');
$url = (string) $request->getUri();
header("Location: {$url}");
Security Features:
Generates temporary pre-signed URLs valid for 5 minutes
No direct file access - all downloads go through MinIO
URLs automatically expire for security
Redirects user to the pre-signed URL
Last updated