how to setup amazon s3 bucket in drupal 9 | Amazon S3 Bucket Configuration With Drupal 9˜

Advantages:

You don’t have to purchase an additional hardware as your space requirements grow.
You receive secure and managed hosting at very low costs.
Your server will have an offsite backup in case something goes wrong.
Ample amount of data can be stored in a bucket.
Requirements:

  1. Amazon S3 bucket
    https://aws.amazon.com/s3/
  2. Composer- Composer installs S3 module dependencies such as AWS SDK
    (https://aws.amazon.com/sdk-for-php/).
  3. S3FS Module: Drupal module is required for getting connected to Amazon S3 bucket.
  4. Drush

Installation:

Step 1: Run the below composer command or go to https://www.drupal.org/project/s3fs for latest version.

composer require 'drupal/s3fs:^3.0@beta'

After running this command, you will get the following screen:

Drupal 9 S3FS module.

Step 2: Enable S3FS Module, Run Below command to enable the module or you can enable it using Drupal UI.

lando drush en s3fs
Enable S3fs Module drupal 9

Step 3: Login Into Admin Panel and go to /admin/config/media/file-system and configured Amazon Simple Storage Service and click on Save Configuration.

Step 4: Go to /admin/config/development/performance and Disabled css and js aggregation. If you will not do this then admin panel got distorted.

Disabled css js aggregate

Step 5: Go to settings.php file under /web/sites/default/settings.php and add below line and change configuration accordignally.

$settings['file_private_path'] = 'sites/default/files/public';
$settings['s3fs.access_key'] = 'AccessKey';
$settings['s3fs.secret_key'] = 'SecretKey';
$config['s3fs.settings']['bucket'] = 'BucketName';
$config['s3fs.settings']['region'] = 'RegionName';
$settings['s3fs.upload_as_private'] = TRUE;
$settings['s3fs.use_s3_for_public'] = TRUE;

Step 6: Run below command to Clear Cache

lando drush cr

Step 7: Go to images field storage setting and change your storage location to

S3 File System

Step 8: Go to /admin/config/media/s3fs/actions click on validate, it will show success message if connected to S3 Bucket.

S3 Bucket Validate Successful

Pradip Mehta

I am a well-organized professional in Drupal Development and PHP web development with strong script handling knowledge or automation process with PHP. I have advanced computer skills and am a proficient multitasker.