- Amazon delivers your static files fast.
- This reduces the demand on your own server, making it faster as well
- You upload all your wordpress static files (you wp-content and wp-includes folders) onto Amazon S3, then tell Cloudfront to get your files from Amazon S3 as it needs them.
- You tell Cloudfront to get the files directly from your site as it needs them. This second way is called ‘Origin Pull’.
How to associate CloudFront with WordPress
Create a user and user group in IAM
- Create a new group (give any name) and give administrative privilege.
- Create a user + click on add user + give username + grand programmatic access click on Permissions and assign it to the group that we created click on create user.
- Copy the access key and secret access key (or download them).
Create an S3 bucket
- Create an S3 bucket. Try to give your domain name as the bucket name.
- Make sure that for the user ‘username’ has read permission.
Create a CloudFront distribution
- Go to CloudFront in the section web click on get started.
- In the origin name select the aws s3 bucket name which you created.
- Leave rest of the options as default.
- Create the distribution.
- Log in to the WordPress dashboard install w3-total cache plugin.
- Go to the performance option in the WordPress dashboard go to general setting and go to the CDN setting and enable it and in the CDN type select the AWS CloudFront option from the origin pull push.
- Click on save all settings.
- Go back to the performance tab and click on CDN and in the configuration section enter the access key and secret key which you have copied previously.
- Make sure that you have the correct values in the CloudFront domain name in the option replace site’s hostname with and the bucket name.
- Click on the upload attachment button and click on start
- This will upload all your WordPress contents to the s3 bucket.
- Same way you can click on the upload attachment buttons of other sections and upload the desired contents to the s3.
- Click save settings and purge caches button.
Set Up CloudFront With WP Super Cache (Alternative plugin)
- Log in to the WordPress dashboard install WP Super Cache
- Go to the WP Super Cache settings and copy and paste in the CloudFront distribution URL. Then enable the CDN, and save settings.
- After that, refresh the page and you will able to see that the site is pulling the contents from CDN instead of your normal server.
- (For the conformation you can check the URL of the images that are been loaded by opening the image in a new tab).