How to host WordPress Images on Amazon S3

In this post, I will be going over how to host WordPress images (and other media files) on an Amazon S3 server.

I decided to do this because I was quickly running out of storage space on my web hosting provider for my business website. I needed a cost-effective solution and this is what I came up with.

Follow along with me in the video below:

Step 1: Install WP Offload Media Lite Plugin

Download and install the plugin using your WordPress Dashboard. A link to the plugin can be found here.

Step 2: Set up Amazon S3

If you don’t have an Amazon Web Services (AWS) account, you can sign up for one here.

Add the following code to your bucket policy:

{
	"Version": "2008-10-17",
	"Statement": [
	{
		"Sid": "AllowPublicRead",
		"Effect": "Allow",
		"Principal": {
			"AWS": "*"
		},
		"Action": "s3:GetObject",
		"Resource": "arn:aws:s3:::bucketname/*"
	}
	]
}

Make sure to replace bucketname with your S3 bucket name.

Add the following code to your IAM user policy:

{
	"Version": "2012-10-17",
	"Statement": [
	{
		"Effect": "Allow",
		"Action": [
			"s3:CreateBucket",
			"s3:DeleteObject",
			"s3:Put*",
			"s3:Get*",
			"s3:List*"
		],
		"Resource": [
			"arn:aws:s3:::bucketname",
			"arn:aws:s3:::bucketname/*"
		]
	}
	]
}

Once again, make sure to replace bucketname with your S3 bucket name.

Step 3: Update wp-config file

Add the following code to your wp-config file.

define( 'AS3CF_AWS_ACCESS_KEY_ID', '********************' );
define( 'AS3CF_AWS_SECRET_ACCESS_KEY', '**************************************' );

Note: The Access Key ID and Secret Access Key is generated when you setup the IAM user in the previous step.

Step 4: Configure and Test Plugin

Go back to your WordPress Dashboard to configure and test the WP Offload Media Lite plugin.

Additional Resources

You should be able to get everything set up if you follow along the steps of the video above. But if you needed more information or a detailed write-up of the steps, feel free to visit any of the references below:

https://www.codeinwp.com/blog/wordpress-s3-guide/

https://mhthemes.com/blog/offload-wordpress-images-amazon-s3/

Leave a Reply