Configuring your WordPress instance to work with your Amazon Lightsail distribution

in Amazon Lightsail

Amazon Lightsail is the easiest way to get started with AWS. It offers virtual servers, storage, databases and networking, plus a cost-effective, monthly plan.

This tutorial shows you how to configure your WordPress intance to work with your Amazon Lightsail distribution. 

Get started with Amazon Lightsail for free.

About this Tutorial
Time 10-20 minutes      
Cost Free
Use Case Compute
Products Amazon Lightsail
Level 200
Last Updated July 16, 2020

Step 1: Prerequisites

1.1 — Login to your Lightsail account, and make sure you have a WordPress instance up and running. Follow this tutorial for details on how to spin up a WordPress instance. 

Already have an account? Log in to your account

1.2 — To configure your WordPress instance to work with your distribution, determine if:

  • Your WordPress website uses Hypertext Transfer Protocol (HTTP) only - If your website uses HTTP only, and is not configured to use HTTPS, then you must follow the instructions in the Configure your WordPress instance to work with your distribution using SSL/TLS termination (LINK) section of this tutorial.
 

Option 1: Configure your WordPress instance to work with your distribution using SSL/TLS termination

Complete the following procedure to edit the wp-config.php file in your WordPress instance for it to work with your distribution.

Note: We recommend that you create a snapshot of your WordPress instance before getting started with this procedure. The snapshot can be used as a backup from which you can create another instance in case something goes wrong. For more information, see Creating a snapshot of your Linux or Unix instance in Amazon Lightsail.

2.1 — Sign in to the Lightsail console.

2.2 — On the Lightsail home page, choose the browser-based SSH client icon that is displayed next to your WordPress instance.

2.3 — After you're connected to your instance, enter the following command to create a backup of the wp-config.php file. If something goes wrong, you can restore the file using the backup.

sudo cp /opt/bitnami/apps/wordpress/htdocs/wp-config.php 
/opt/bitnami/apps/wordpress/htdocs/wp-config.php.backup

2.4 — Enter the following command to open the wp-config.php file using Vim.

sudo vim /opt/bitnami/apps/wordpress/htdocs/wp-config.php

2.5 — Press I to enter insert mode in Vim.

2.6 — Delete the following lines of code in the file.

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');

2.7 — Add the following lines of code to the file, where you previously deleted the code.

define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/');
if (isset($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'])
&& $_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}

2.8 — Press the Esc key to exit insert mode in Vim, then type :wq! and press Enter to save your edits (write) and quit Vim.

2.9 — Enter the following command to restart the Apache service on your instance.

sudo /opt/bitnami/ctlscript.sh restart Apache

2.10 — Wait a few moments for your Apache service to restart, then test that your distribution is caching your content. For more information, see Testing your Amazon Lightsail distribution. (LINK)

2.11 — If something went wrong, re-connect to your instance using the browser-based SSH client. Run the following command to restore the wp-config.php file using the backup you created earlier in this guide.

sudo cp /opt/bitnami/apps/wordpress/htdocs/wp-config.php.backup
/opt/bitnami/apps/wordpress/htdocs/wp-config.php

Option 2: Configure your WordPress instance to work with your distribution using end-to-end encryption

3.1 — All Lightsail distributions have HTTPS enabled by default for their default domain (e.g., 123456abcdef.cloudfront.net). When you configure a WordPress instance that uses HTTPS as the origin of your distribution, you can configure your distribution to forward all content requests to your instance using an encrypted connection. The connection between your website visitors and your distribution is encrypted (using HTTPS), and so is the connection between your distribution and your instance. This configuration is known as end-to-end encryption. To enable this configuration, you must configure your distribution's origin protocol policy to HTTPS only.

For more information, see Origin protocol policy. If you don't configure your distribution's origin policy to HTTPS only, your website visitors will see an error.

Congratulations

You've configured your WordPress instance to work with your Lightsail distribution!

Amazon Lightsail is a great choice to develop, build, and deploy a variety of applications like WordPress, websites, and blog platforms.

Was this tutorial helpful?

Thank you
Please let us know what you liked.
Close
Sorry to disappoint you
Is something out-of-date, confusing or inaccurate? Please help us improve this tutorial by providing feedback.
Close

Learn more about distributions

Learn and find more about Lightsail distributions, and read more documentation to best manage your distributions in Lightsail. LINK

Create SSL/ TLS certificates

Create SSL/TLS certificates for your Amazon Lightsail distribution. LINK