Skip to content
Thai Phan edited this page Feb 5, 2019 · 14 revisions

These are the recommended instructions on how to your Magento 2 instance to sync images to S3 using my extension.

Warnings

  • Please back up your media files before installing this extension! You never know what might happen!
  • Please use this extension in a test environment before you deploy to production.
  • I don't recommend using the Magento admin panel to sync your media. If you have lots of images, it might time out and you'll end up in a broken state.

Installation

You need to install this extension using Composer.

cd /path/to/magento2/
composer require thaiphan/magento2-s3

You then need to register the module as enabled in Magento 2.

php bin/magento module:enable Thai_S3
php bin/magento setup:upgrade

Configuration

Step 1: Configure Magento to use your S3 bucket

php bin/magento s3:config:set \
    --access-key-id=XXXXXXX \
    --secret-key=XXXXXXX \
    --bucket=XXXXXXX \
    --region=XXXXXXX

Supported Regions

Please use one of the values on the left column of the below table for the --region flag. Please do not use the values on the right column of the below table or else the extension will not work.

Region (use these values) Description (don't use these values)
ap-northeast-1 Asia Pacific (Tokyo)
ap-northeast-2 Asia Pacific (Seoul)
ap-south-1 Asia Pacific (Mumbai)
ap-southeast-1 Asia Pacific (Singapore)
ap-southeast-2 Asia Pacific (Sydney)
ca-central-1 Canada (Central)
cn-north-1 China (Beijing)
cn-northwest-1 China (Ningxia)
eu-central-1 EU (Frankfurt)
eu-west-1 EU (Ireland)
eu-west-2 EU (London)
eu-west-3 EU (Paris)
sa-east-1 South America (Sao Paulo)
us-east-1 US East (N. Virginia)
us-east-2 US East (Ohio)
us-west-1 US West (N. California)
us-west-2 US West (Oregon)

Feel free to make a pull request to add new regions to this extension.

Step 2: Upload all pre-existing images to your S3 bucket

php bin/magento s3:storage:export

Step 3: Enable S3 integration for your Magento instance

php bin/magento s3:storage:enable

Step 4: Add base URL (optional)

go to Stores > Configuration > Catalog > Web > Base URLs > Base URL for User Media Files and add your S3 url, e.g. https://s3.eu-central-1.amazonaws.com/bucket-name/. Note the trailing /!

Repeat this step for Stores > Configuration > Catalog > Web > Base URLs (Secure) > Secure Base URL for User Media Files