How to Set Up a WordPress Website with SSL Using Amazon EC2 & Cloudflare (For Free)

Doğu Deniz Uğur
6 min readMar 7, 2020

In my last post, I explained how to set up a WordPress website with SSL using only AWS microservices ( EC2 and Route53 are used). It is a good read if you want to host your website only using AWS, you can check it out here. However, after publishing that post, I discovered an easier and ~0.6$/month cheaper option. (Route53 is not included in AWS free tier and although not much it costs ~0.6$ per month.)

Cloudflare

So what is Cloudflare? Basically it is a CDN Edge network, which means they store your website content on servers all around the world so that it is accessed faster. In addition, they eliminate the need for Route 53 as it provides the nameservers and sets up DNS records. Furthermore, it can provide you an SSL certificate and set up the necessary HTTPS redirections with just a click of a button. Lastly, it costs nothing. If you want to learn more about Cloudflare you can start reading here.

In this post, I will explain how to host a WordPress website on EC2 and implement Cloudflare for DNS configurations and HTTPS connection. I copied Step 1 and Step 2 from my last post so if you have already read that you can directly skip to Step 3.

Step 1: Launching an EC2

After opening an AWS account and logging into the console, you can easily open your EC2 dashboard by searching “EC2” under the AWS services.

Then let’s open your first EC2 by clicking the big orange “Launch instance” button.

This will bring you to the EC2 image market place of AWS, we want to set up WordPress so select AWS Marketplace from the side menu and just search for “WordPress”.

WordPress with NGINX and SSL Certified by Bitnami and Automattic” is the image we are searching for, selecting it will take you to machine type selection. Just chose t2.micro, as it is free-tier eligible, and click Review and Launch then Launch. If this is your first time creating an EC2 you should select the Create a new key pair option for SSH and name it however you like. After downloading the key move it somewhere you will not forget; although connecting via SSH is not required throughout this process it will most likely come in handy sometime later. After that, you can launch the instance.

By clicking on the instances name (something like i-054d749…) you can jump to the EC2 Management Console. Now we have to wait for a little bit for our EC2 to initialize, there is enough time to grab a coffee.

Copying and pasting the Public IP address, as seen above, should take you to your WordPress site. If you see the website below, then you are on the right track.

Step 2: Allocating a Static IP Adress to the EC2

The next step is making the connection between the EC2 and our domain. Originally EC2s don’t have a static IP address, for this reason, we will be using Elastic IP. From the menu on the left of EC2 Management Console we can go to the Elastic IP page:

Then by clicking Allocate Elastic IP Address (the big orange button) > Allocate, we can create a new static Elastic IP. After that, we should associate it with our EC2 by choosing the Associate Elastic IP address option from the Actions dropdown.

Choose your WordPress EC2 instance from the Instances dropdown and click Associate. Then, you are good to go.

Now we have an EC2 which is hosting a WordPress site and it has a static IP, next thing we have to do is to have name servers so that we can direct our domain. For this, you should open a Cloudflare account.

Step 3: Connecting the EC2 the Internet and Configuring HTTPS Connection

You can use any domain registrar to buy your preferred domain; as an example for this post, I registered wordpresswithcloudflare.tk from Freenom.

After having a domain in hand, you should create a Cloudflare account and sign in. The page below will greet you:

After clicking Add Site copy-paste your registered domain and click Add Site again. You can choose the Free Plan.

Now the DNS Records should be set; for the Name field, type @ (for the root) and for the IPv4 address type the Elastic IP you have associated with your EC2 at Step 2. For www.<YOUR_DOMAIN>.com to work as well, add another record with the same IP and www in the name field.

On the next page, the Cloudflare nameservers will be seen; go to your registrar and change the nameservers accordingly.

After making the changes on your registrar you can click Done, check nameservers button and continue.

The next page is about your website settings, the defaults are good on their own but in order to redirect every HTTP request to HTTPS you need to turn on the Always use HTTPS option.

Now the boring part, unfortunately, nameserver changes doesn’t change immediately so you need to wait for the changes to take effect. Just keep refreshing and clicking the Recheck nameservers button.

And finally, when you go to your domain you should see the default WordPress page and the little lock logo on the left of the URL, even when you go to HTTP://<YOUR_DOMAIN>.com Cloudflare should redirect to HTTPS://<YOUR_DOMAIN>.com.

CONCLUSION

In the end, you should have a working WordPress site with automattic HTTPS redirections. You can also try and tinker with many options Cloudflare is offering for free. If you have any questions regarding the procedure, please feel free to write to my e-mail address: dogudeniz@pm.me. If e-mail feels insincere, go with LinkedIn or Instagram.

Hope you have enjoyed reading.

Originally published at https://δ.ml on March 7, 2020.

--

--