Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nicopin's avatar

Unable to use S3 with Storage in Laravel 9

Hi I'm having trouble when i use Storage::disk('s3') in Laravel9.

The situation is that If S3 is to be used as storage, the Storage facade is currently not functional because it cannot run properly with only the configuration in the documentation. I have confirmed that communication is possible when using the S3 client directly.

The Storage::disk('s3')->directories() is not working. It returns errors like below.

Aws\S3\Exception\S3Exception with message 'Error executing "ListObjectsV2" on "https://aws-bucket"; AWS HTTP error: cURL error 60: SSL: no alternative certificate subject name matches target host name 'aws-bucket-name' (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for aws-bucket-url

I searched and I've found that it may have to do with openssl. So I configured openssl and setup cacert.pem from mozilla. Then I tried to use S3Client and AwsS3V3Adapter directory. And below code worked.

$client = new S3Client([
            'credentials' => [
                'key'    => env('AWS_ACCESS_KEY_ID'),
                'secret' => env('AWS_SECRET_ACCESS_KEY')
            ],
            'region' => env('AWS_DEFAULT_REGION'),
            'http' => ['verify' => '/usr/local/etc/ssl/cacert.pem'], // this configuration was needed on local env.
            'version' => 'latest',
        ]);

        $adapter = new AwsS3V3Adapter($client, 's3-bucket-name');
        $filesystem = new Filesystem($adapter);
        try {
            $filesystem->write('sample2.txt', 'content');
        } catch (FilesystemException $e) {
            dd($e);
        }

Does anyone have ideas to make Storage facade work properly? Thank you.

0 likes
11 replies
martinbean's avatar

@nicopin I use S3 in pretty much all my projects and never had an issue with it.

What version of the Flysystem S3 adapter do you have installed? And what configuration variables do you have in your .env file?

nicopin's avatar

@martinbean Hello, Thank you for your reply. This is my settings.

Versions

  • league/flysystem
    • v3.1.0
  • league/flysystem-aws-s3-v3
    • v3.0.22
  • laravel/framework
    • v9.19.0

Configs credentials excluded

AWS_USE_PATH_STYLE_ENDPOINT=false
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXX
AWS_DEFAULT_REGION=ap-northeast-1
AWS_BUCKET=XXXXXX
AWS_ENDPOINT=https://XXXXXXXXXXXX
AWS_URL=https://XXXXXXXXX
    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
            'throw' => false,
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
            'throw' => false,
        ],

        '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' => false,
        ],

    ],
martinbean's avatar
Level 80

@nicopin Remove the AWS_ENDPOINT and AWS_URL variables. They’re not needed. The Flysystem driver can build proper S3 object URLs without those.

4 likes
Yamen's avatar

I fixed a similar issue with this config:

'use_path_style_endpoint' => true,
nexxai's avatar

I realize this is an old thread but wanted to add a potential solution for people who stumble across this post.

If everything works fine locally, but fails when you're using GitHub Actions (and I'm sure it's similar for other CI platforms), you need to do THREE things to make sure your tests can access your bucket:

  1. Make sure the AWS Access Key has both s3:ListBucket and s3:GetObject ACLs
  2. Add the Access Key ID and Secret Access Key as repository secrets
  3. Make sure that you explicitly allow the step in the action to access those secrets

e.g.

      - name: Execute tests
        env:                               // v---- THIS STUFF RIGHT HERE
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        run: |
          cp .env.github .env
          php -v
          php artisan migrate --force
          php artisan key:generate
          ./vendor/bin/pest

Please or to participate in this conversation.