How to Use Backblaze S3 Bucket in Laravel

Learn how to integrate Backblaze S3 storage with Laravel for seamless cloud storage setup. Follow this simple guide to get up and running quickly.

March 23, 2025 - 1 min read

⚠️ If you're new to Backblaze, use this guide before proceeding.

1. 🤖 Install Necessary Dependencies

$ composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies

2. 🛠️ Set Up Your .env File as Follows

AWS_ACCESS_KEY_ID=YOUR_APPLICATION_KEY_ID # ex. 0050cXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=YOUR_APPLICATION_ACCESS_KEY_ID # K005XXXXXXXXXXXXXXXXX
AWS_DEFAULT_REGION=BUCKET_REGION # ex. us-east-001
AWS_BUCKET=YOUR_BUCKET_NAME # ex. testbackblaze
AWS_ENDPOINT=https://s3.BUCKET_REGION.backblazeb2.com # ex. https://s3.us-east-001.backblazeb2.com

3. 🧰 Test Command (Optional)

If you want to test the connection to Backblaze S3 before doing anything else, it’s a good idea to create a quick Laravel command:

$ php artisan make:command TestS3

Then, paste the following code inside the TestS3.php file:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class TestS3 extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test-s3';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Test S3 connection with Backblaze';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $s3 = Storage::disk('s3');
        $s3->put('test.txt', 'Hello World');

        if ($s3->exists('test.txt')) {
            $this->info('Everything is ok');
        } else {
            $this->error('Something went wrong');
        }
    }
}

Run the command

php artisan app:test-s3

If everything’s set up correctly, you’ll see Everything is ok. If not, well... you’ll get an error message

✅ And You’re Done! That’s all there is to it! You’ve successfully configured your Laravel app to work with Backblaze S3 storage. Happy coding! 🎉