How To: Store WordPress Images on Amazon S3

I’ve integrated Amazon S3 with the very handy (and open source) S3 Uploads WordPress plugin, which automatically uploads files to S3 and rewrites URLs from your website to serve them from there.

Step 1: Install WordPress CLI

  • Connect via the terminal access on your server
  • Install the WordPress CLI (if not already installed):
curl -O
sudo chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Step 2: Install S3-Uploads WordPress Plugin

  • Download the S3-Uploads WordPress plugin and place it in your wp-content/plugins folder:
mv S3-Uploads-master/ /wp-content/plugins/S3-Uploads

Step 3: Activate S3 Uploads

  • Now activate the plugin via the WordPress CLI:
wp plugin activate S3-Uploads
  • In order for the plugin to work, you need to store appropriate Amazon Credentials in your config file. In the Amazon Console, add a new IAM user with only access to control your S3 bucket. Then place the credentials and S3 bucket details in your wp-config.php file:
define( 'S3_UPLOADS_BUCKET', '' );
define( 'S3_UPLOADS_KEY', 'xxxxxxxxxxxxx' );
define( 'S3_UPLOADS_SECRET', 'xxxxxxxxxxxxx' );
define( 'S3_UPLOADS_REGION', 'ap-southeast-2' );
define( 'S3_UPLOADS_BUCKET_URL', '' );
  • You’re now all set! All new files uploaded will be automatically copied to S3, and their URL rewritten to that endpoint

Step 4: Sync existing files to S3 (Optional)

  • If you have an existing site, you may wish to migrate all your files up to S3. To do this:
wp s3-uploads verify
wp s3-uploads --sync upload-directory wp-content/uploads/ s3://uploads/

Note: There is currently a bug in the S3-Uploads plugin which causes an error when you run the above:

Fatal error: Class 'Aws\S3\Sync\UploadSyncBuilder' not found

To fix this:

vim wp-content/plugins/S3-Uploads/inc/class-s3-uploads-uploadsyncbuilder.php

And remove reference “extends Aws\S3\Sync\UploadSyncBuilder”

Leave a Reply