Menu Close

Configuration of Let’s Encrypt certificate on AWS EC2 WordPress

Below are steps on how to successfully configure an https certificate on a wordpress site hosted on Amazon EC2. Before you start, make sure wordpress is running normally, ie you see the hello world default article texts on your browser. This guide will work for both x86 or x64 OS host architecture. For 64-bit OS you may want to use the auto configure bnc-cert tool which is easier and faster to run.

1. To start, execute this script both with and without the www prefix parameters. Replace the YOURMAIL and YOURDOMAIN place-holders with your email address and with the domain name. I am on windows and I use Putty for my command line interface.

sudo /opt/bitnami/letsencrypt/scripts/generate-certificate.sh -m YOURMAIL -d YOURDOMAIN -d www.YOURDOMAIN

2. Edit/configure the file bitnami.conf. The path would normally be: /opt/bitnami/apache2/conf/bitnami.

Command line to type so you could edit:
sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami.conf

On your bitnami.conf file, insert the following lines on your Virtual Host port 80 parameters:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://www.example.com/$1 [R,L]

It should look like this:
(of course you’ll have to replace the texts example.com with your domain name)

Screenshot for Virtual Host port 80 parameters
Screenshot for Virtual Host port 80 parameters

Insert the following lines on your Virtual Host port 443 parameters:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://www.example.com$1 [R=permanent,L]

It should look like this:

Screenshot for Virtual Host port 443 parameters
Screenshot for Virtual Host port 443 parameters

3. Restart apache:
sudo /opt/bitnami/ctlscript.sh restart apache

4. You should now see a padlock on your site’s web address:

5. End.