How to host a WordPress website in AWS EC2 instance – Part 3
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
This will be a 3-part series where in part 1 we have created an EC2 instance in AWS cloud to host our WordPress website, in the part 2 we have installed and configured our WordPress website and in part 3 will complete the setup by enabling DNS and TSL/SSL for our WordPress website.
How to install TSL/SSL (HTTPS) for WordPress on AWS EC2 instance:
Prerequisites:
Step 1: Configure DNS to route traffic to your WordPress instance using domain name.
So far, we were using the Elastic IP address to browser to our WordPress website. But once your website is live, the target audience for your website will use the domain name and not IP address to navigate to your website.
We need to create an “A” record in our DNS management service provided by our domain registrar to create this record. In this demo we are using AWS Route53 as our domain registrar hence we will create the DNS record in AWS Route53 console. But the process will be same for any other domain registrar like GoDaddy.
We will also create a CNAME record (www.techaffaire.com) against our domain name (techaffaire.com) so that if someone tries to access our website using https://www.techaffaire.com the traffic will automatically get redirected to https://techaffaire.com
Login to AWS management console and navigate to Route53 service.
Select the hosted zone for your registered domain name and click “Create record”.
Select “A” as record type and provide the Elastic IP address of your WordPress instance. Click “Create records” to create the record.
Similarly create a second record of type “CNAME” with name as “www” and value as “<your_domain_name>.
Now if we try to access our WordPress website, it can be accessed using the domain name.
Note: It may take some time for the DNS record to get propagated around the world. Hence if DNS resolution does not work for the first time, give it some time and retry.
Next, we need to install TSL/SSL for our WordPress website.
Step 2: Install TSL/SSL for WordPress website in AWS EC2 instance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
## ----------------------- ## Install and run Certbot ## ----------------------- ## Connect to your WordPress EC2 instnace ## Edit the main Apache configuration ## Locate the "Listen 80" directive and add the following lines after it, ## replacing the techaffaire domain names with your domain name sudo vi /etc/httpd/conf/httpd.conf --------- DocumentRoot "/var/www/html" ServerName "techaffaire.com" ServerAlias "www.techaffaire.com" -------- ## Restart Apache web server sudo systemctl restart httpd ## Download the Extra Packages for Enterprise Linux (EPEL) 7 repository packages. sudo wget -r --no-parent -A 'epel-release-*.rpm' https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/ ## Install the repository packages sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm ## Enable Enterprise Linux (EPEL) 7 repository packages sudo yum-config-manager --enable epel* ## Install Certbot packages and dependencies sudo yum install -y certbot python2-certbot-apache ## -------------- ## Enable TSL/SSL ## -------------- ## Run certbot in interactive mode sudo certbot ## Provide below details when prompted ## At the prompt "Enter email address (used for urgent renewal and security notices)," enter a contact address and press Enter. ## Agree to the Let's Encrypt Terms of Service at the prompt. Enter "A" and press Enter to proceed. ## ## At the authorization for EFF to put you on their mailing list, enter "Y" or "N" and press Enter. ## ## Certbot displays the Common Name and Subject Alternative Name (SAN) that you provided in the ## VirtualHost block. Leave the input blank and press Enter. ## ## Certbot prompts you about redirecting HTTP queries to HTTPS. ## To allow visitors to connect to your server via unencrypted HTTP, enter "2" and Press Enter. ## ## Certbot completes the configuration of Apache and reports success and other information. ## ---------------------------- ## Automate certificate renewal ## ---------------------------- ## Create a new entry in crontab sudo crontab -e ------------------------ 30 2 * * Sun root certbot renew --no-self-upgrade ------------------------ ## Restart the cron daemon. sudo systemctl restart crond |
Now if you refresh your website in your browser, you will see HTTPS is enabled for your WordPress website hosted on AWS EC2 instance.
Lastly update the URL in your WordPress configuration.
Hope you have enjoyed this 3rd Part and now you are ready to create an awesome website in AWS cloud 😊