S3 and MinIO File Storage Setup
S3-compatible storage stores uploaded files (photos, documents, videos) separately from the application server. MinIO is a self-hosted AWS S3 alternative with identical API.
AWS S3: Basic setup
# Terraform
resource "aws_s3_bucket" "uploads" {
bucket = "myapp-uploads-production"
}
resource "aws_s3_bucket_public_access_block" "uploads" {
bucket = aws_s3_bucket.uploads.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_versioning" "uploads" {
bucket = aws_s3_bucket.uploads.id
versioning_configuration { status = "Enabled" }
}
resource "aws_s3_bucket_server_side_encryption_configuration" "uploads" {
bucket = aws_s3_bucket.uploads.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
Presigned URLs for secure uploads
Client uploads file directly to S3, bypassing server. Server generates signed URL with limited lifetime.
// Laravel + aws-sdk-php
use Aws\S3\S3Client;
class FileUploadController extends Controller
{
public function presign(Request $request): JsonResponse
{
$request->validate([
'filename' => 'required|string|max:255',
'content_type' => 'required|string',
]);
$key = 'uploads/' . auth()->id() . '/' . Str::uuid() . '/' .
pathinfo($request->filename, PATHINFO_BASENAME);
$s3 = app('aws')->createClient('s3');
$command = $s3->getCommand('PutObject', [
'Bucket' => config('filesystems.disks.s3.bucket'),
'Key' => $key,
'ContentType' => $request->content_type,
'ACL' => 'private',
]);
$presigned = $s3->createPresignedRequest($command, '+15 minutes');
return response()->json([
'upload_url' => (string) $presigned->getUri(),
'key' => $key,
]);
}
}
MinIO: self-hosted deployment
# docker-compose.yml
services:
minio:
image: minio/minio:latest
command: server /data --console-address ":9001"
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: ${MINIO_PASSWORD}
volumes:
- minio_data:/data
ports:
- "9000:9000" # S3 API
- "9001:9001" # Web console
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 10s
volumes:
minio_data:
MinIO has identical AWS S3 API — just change the endpoint in configuration:
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=miniopassword
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=uploads
AWS_URL=http://minio:9000
AWS_ENDPOINT=http://minio:9000
AWS_USE_PATH_STYLE_ENDPOINT=true
Laravel Filesystem integration
// config/filesystems.php
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => true,
],
// Usage
$path = Storage::disk('s3')->putFile('uploads', $request->file('photo'));
$url = Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(60));
Lifecycle and cleanup
resource "aws_s3_bucket_lifecycle_configuration" "uploads" {
bucket = aws_s3_bucket.uploads.id
rule {
id = "move-to-glacier"
status = "Enabled"
transition {
days = 90
storage_class = "GLACIER"
}
expiration {
days = 365
}
filter {
prefix = "temp/"
}
}
}
Timeline
AWS S3 with presigned URLs for Laravel/Node.js: 1–2 days. MinIO self-hosted with Docker: 1 day. Both with lifecycle rules and monitoring: 3 days.







