Getting Started / Hands-on / ...
Connecting a WordPress website to an Amazon Lightsail bucket and distribution
Amazon Lightsail is the easiest way to get started with AWS. It offers virtual servers, storage, databases, networking, and now containers, plus a cost-effective, monthly plan.
Lightsail now offers object storage. For more information on this latest launch, please read this What's New post.. This tutorial describes the steps required to configure your Lightsail bucket as the origin of a Lightsail content delivery network (CDN) distribution. It also describes the steps required to configure your WordPress website to upload and store media (images, movies files, etc.) on your bucket, and deliver it from your distribution.
You do this by installing and configuring the WP Offload Media Lite plugin on your WordPress website. The following diagram illustrates this configuration.
Storing website media in a Lightsail bucket takes the load off your instance from having to store and serve those files. Caching and serving media from a Lightsail distribution speeds up the delivery of those files to your website visitors, and can improve overall website performance. For more information about distributions, see Content delivery network distributions in Amazon Lightsail. For more information about buckets, see Object storage in Amazon Lightsail.
Get started with Amazon Lightsail for free.
About this Tutorial | |
---|---|
Time | 30-45 minutes |
Cost | Free |
Use Case | Compute |
Products | Amazon Lightsail |
Level | 200 |
Last Updated | July 14, 2021 |
Step 1: Prerequisites
Complete the following prerequisites if you haven't already:
1.1 — Create a Lightsail account.
Already have an account? Log in to your account
1.2 — Create and configure a WordPress instance in Lightsail, and get the password to sign in to the administration dashboard. For more information, see Tutorial: Launch and configure a WordPress instance in Amazon Lightsail.
1.3 — Create a bucket in the Lightsail object storage service. For more information, see Creating buckets in Amazon Lightsail.
Step 2: Modify your bucket permissions
Complete the following procedure to give your WordPress instance and the WP Offload Media Lite plugin access to your bucket. The permissions of your bucket must be set to Individual objects can be made public (read only). You must also attach your WordPress instance to your bucket. For more information about bucket permissions, see Understanding bucket permissions in Amazon Lightsail.
2.1 — Sign into the Lightsail console.
2.2 —On the Lightsail home page, choose the Storage tab.
Choose the name of the bucket that you want to use with your WordPress website.
2.3 — Choose the Permissions tab on the Bucket management page.
Choose Change permissions under the Bucket access permissions section of the page.
2.6 — Choose Individual objects can be made public (read-only).
Choose Save.
2.7 — Choose Yes, Save in the confirmation prompts that appear.
After a few moments, your bucket will be configured to allow for individual object access. This ensures that objects uploaded to your bucket from your WordPress website using the WP Offload Media Lite plugin are readable to your customers.
2.8 — Scroll to the Resource access section of the page, and choose Attach instance.
2.9 — Choose the name of your WordPress instance in the dropdown menu that appears. Choose Attach.
After a few moments, your WordPress instance is attached to your bucket. This gives your WordPress instance access to manage your bucket and its objects.
Step 3: Create a distribution with a bucket as the origin
Complete the following procedure to create a Lightsail distribution and choose your Lightsail bucket as the origin.
3.1 — Choose Home on the top navigation menu of the Lightsail console.
3.2 — On the Lightsail home page, choose the Networking tab.
Choose Create Distribution.
3.3 — In the Choose your origin section of the page, choose the AWS Region in which you created your bucket.
Distributions are global resources. They can reference a bucket in any AWS Region, and distribute its content globally.
3.4 — Choose your bucket as the origin.
Note: When you choose a bucket as the origin of a distribution, the options to specify the origin protocol policy, caching behavior, default behavior, and directory and file overrides become unavailable and cannot be edited. The origin protocol policy defaults to HTTP only for buckets, and the caching behavior defaults to Cache everything. However, you can change the advanced cache settings of the distribution after it's created.
3.5 — Choose your distribution plan.
3.6 — Enter a name for your distribution.
Resource names:
- Must be unique within each AWS Region in your Lightsail account.
- Must contain 2 to 255 characters.
- Must start and end with an alphanumeric character or number.
- Can include alphanumeric characters, numbers, periods, dashes, and underscores.
3.9 — Choose Create distribution.
Your distribution is created after a few moments. When your new distribution reaches an Enabled state, it is ready to serve and cache objects that are in your bucket.
Step 4: Enable a custom subdomain for your distribution
When you create your distribution, it is configured with a default domain that is similar to 123abc.cloudfront.net. You can specify that default domain as the source of your media files when you configure the WP Offload Media Lite plugin.
But we highly recommend that you enable a custom domain for your distribution. The custom domain that you enable for your distribution should be a subdomain of the domain that you're using with your WordPress website. For example, if you're using mycustomdomain.com with your WordPress website, then you might choose to use the custom domain media.mycustomdomain.com with your distribution. Using the same domain and subdomain combination between your WordPress website and your distribution helps improve the search engine optimization score of your website.
Complete the following steps to configure a custom domain for your distribution:
4.1 — Create a Lightsail SSL/TLS certificate for your domain to use it with your distribution. Lightsail distributions require HTTPS, so you must request an SSL/TLS certificate for your domain before you can use it with your distribution. For more information, see Creating SSL/TLS certificates for your distribution in Amazon Lightsail.
4.2 — Enable custom domains for your distribution to use your domain with your distribution. Enabling custom domains requires that you specify the Lightsail SSL/TLS certificate that you created for your domain. This adds your domain to your distribution and enables HTTPS. For more information, see Enabling custom domains for your Amazon Lightsail distributions.
4.3 — Add an alias record to your domain's DNS to begin routing traffic for your domain to your distribution. After you add the alias record, users who visit your domain are routed through your distribution. For more information, see Pointing your domains to your Amazon Lightsail distributions.
Step 5: Install the WP Offload Media Lite plugin on your WordPress website
Complete the following procedure to install the WP Offload Media Lite plugin on your WordPress website. This plugin automatically copies images, videos, documents, and any other media added through WordPress' media uploader to your Lightsail bucket. It can also be configured to serve media from your bucket through your Lightsail distribution. For more information, see WP Offload Media Lite in the WordPress website.
5.1 — Sign in to the dashboard of your WordPress website as an administrator.
For more information, see Getting the application user name and password for your 'Certified by Bitnami' instance in Amazon Lightsail.
5.2 — Pause on Plugins in the left navigation menu, and choose Add New.
5.3 — Search for WP Offload Media Lite.
5.4 — In the search results, choose Install Now next to the WP Offload Media Lite plugin.
5.5 — Choose Activate after the plugin is done installing.
5.6 — In the left navigation menu, choose Settings, then choose Offload Media.
5.7 — In the Offload Media Lite page, choose Amazon S3 as the storage provider.
5.8 — Choose My server is on Amazon Web Services and I'd like to use IAM Roles.
Then choose Next.
5.9 — Choose Browse existing buckets in the What bucket would you like to use? page that appears.
5.10 — Choose the name of the bucket that you created to use with your WordPress instance.
5.11 — In the Offload Media Lite Settings page that appears, enable Force HTTPS and Remove Files From Server.
- The Force HTTPS setting must be enabled because Lightsail buckets use HTTPS by default to serve media files. If you don't enable this feature, media files that are uploaded to your Lightsail bucket from your WordPress website will not be be served correctly to your customers when they visit your website.
- The Remove Files From Server setting ensures that media that is uploaded to your Lightsail bucket isn't also stored on your instance's disk. If you don't enable this feature, media files that are uploaded to your Lightsail bucket will also be stored on the local storage of your WordPress instance.
5.12 — Under the Delivery section of the page, choose Change next to the Amazon S3 label.
5.13 — In the How would you like to deliver your media? page that appears, choose Amazon Cloudfront.
And choose Save Delivery Provider.
5.14 — In the Offload Media Lite Settings page that appears, enable Custom Domain (CNAME) and then enter the domain of your Lightsail distribution into the text box. This could be the default domain of your distribution (for example, 123abc.cloudfront.net) or the custom domain for your distribution (for example, media.mycustomdomain.com), if you enabled it.
5.15 — Choose Save Changes.
Note: To return to the Offload Media Lite Settings page later, hover over Settings in the left navigation menu, and choose Offload Media.
Your WordPress website is now configured to use the Media Lite Plugin. The next time you upload a media file through WordPress, that file is automatically uploaded to your Lightsail bucket, and is served by the distribution. Continue to the next section of this tutorial to test the configuration.
Step 6: Test the connection between your WordPress website and your Lightsail bucket and distribution
Complete the following procedure to upload a media file to your WordPress instance and confirm that it is uploaded to your Lightsail bucket and is served from your distribution.
6.1 —Pause on Media in the left navigation menu of the WordPress dashboard, and choose Add New.
6.2 —Choose Select Files on the Upload New Media page that appears.
6.3 — Choose a media file to upload from your local computer, and choose Open.
6.4 — When the file is done uploading, choose Library under Media in the left navigation menu.
6.5 — Choose the file that you recently uploaded.
6.6 — In the details panel of the file, you should see the name of your bucket in the Bucket field, and the URL of your distribution in the File URL field.
6.7 — If you go to the Objects tab of the Lightsail bucket management page, you should see a wp-content folder. This folder is created by the Offload Media Lite plugin, and will be used to store your uploaded media files.
Congratulations
You configured your Lightsail bucket as the origin of a Lightsail content delivery network (CDN) distribution
Amazon Lightsail is a great choice to develop, build, and deploy a variety of applications like WordPress, websites, and blog platforms.
Recommended next steps
Learn more
Learn about objects and buckets in the Amazon Lightsail object storage service. For more information, see the What's New post.
Configure settings
Configure the settings to ensure that your data is private or public as needed. For more information, see Configuring bucket access permissions in Amazon Lightsail.
Learn more
Learn more about Amazon Lightsail by visiting the product detail page.