Host a WordPress Site on Amazon EC2 and map to the custom domain name

Cloud Engineer | AWS Community Builder
Search for a command to run...

Cloud Engineer | AWS Community Builder
No comments yet. Be the first to comment.
You have a working Amazon EKS cluster and deployed pods. Now, your pods need secure, fine-grained access to AWS services like S3, DynamoDB, or Secrets Manager, but: You don't want to hardcode AWS cre

As your team and projects grow, managing a single EKS cluster can get complicated. You'll likely have different teams like a "Backend Team" and a "Frontend Team" all needing to deploy their applicatio

Serverless computing with AWS Lambda is one of the most powerful ways to run code in the cloud without managing servers. But when a Lambda function is placed inside a VPC (Virtual Private Cloud) to co

Modern developers want fast CI/CD but without storing long-lived AWS keys.By combining Amazon ECS (Fargate), Amazon ECR, GitHub Actions, and OpenID Connect (OIDC) you can deploy securely and automatic

Learn Bash Scripting: A Beginner's Guide Table of Contents Introduction Bash Scripting Basics Variables and User Input Conditional Statements Loops and Iterations Functions Working with Files Scripting Best Practices Conclusion 1. Introdu...

Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates your need to invest in hardware upfront, so you can develop and deploy applications faster. You can use it to launch as many or as few virtual servers as you need.

Note: Keep Key pair Private, anyone who gets get pair can log in to your instance.
It allows inbound traffic to connect our EC2 instance.
Amazon EC2 stores data on a network-attached virtual disk called Elastic Block Store. We will launch the Amazon EC2 instance using a default 8 GiB disk volume but you can get up to 30 GiB in the free tier. This will be your root volume (also known as a 'boot' volume).
Every time our instance is rebooted it gets a different IPV4 address from a pool of AWS IPV4. Every time IP changes we need to modify A record to point the IP to our Domain. So, to solve this problem we allocate an Elastic IP address to our domain.
We have several different ways to connect to an instance using putty, PowerShell, and even directly through the Amazon Console. I have used PowerShell but you can use your convenient method.
The general structure to connect to an instance through ssh is:
ssh -i <name of key file><space><Public ipv4 DN>
Note: Launch Powershell from the folder you have your "Shoeasykey.pem" file
sudo su
apt-get update
The apt-get upgrade command downloads and installs the updates for each outdated package and dependency on your system.
apt install apache2
If you get the above page you are good now.
apt install php libapache2-mod-php php-mysql
apt install mysql-server
mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'Y0urStr0ngP@ssw0rdHere';
CREATE USER 'your_username'@localhost IDENTIFIED BY 'Y0urStr0ngP@ssw0rdHere';
CREATE DATABASE wp;
GRANT ALL PRIVILEGES ON wp.* TO 'your_username'@localhost;
Goto WordPress and click on get WordPress, Copy the downloadable link and run the below commands.
cd /tmp
wget https://wordpress.org/latest.zip
To Unzip the file, first of all, you need to install the unzip package. To do so, type in a terminal:
apt-get install unzip
unzip latest.zip
mv wordpress/ /var/www/html
cd /var/www/html
systemctl reload apache2
Now when you paste your IPV4 on the browser you still see the default apache page and the WordPress is accessible only on http://YourIPV4/wordpress
Let us correct this now
cd /etc/apache2/sites-available/
nano 000-default.conf

cd /var/www/html/wordpress
nano wp-config.php
save the code and restart the apache server
I am using NameCheap for a domain. You can use Route53 or any third-party registrar to purchase the domain.
Note: It might take up to 48 hours to reflect the DNS change depending upon your domain registrar.
Note: The time for which a DNS resolver caches a response is set by a value called the time to live (TTL) associated with every record. Amazon Route 53 does not have a default TTL for any record type. You must always specify a TTL for each record so that caching DNS resolvers can cache your DNS records to the length of time specified through the TTL.
I have used a simple routing policy. I will write a separate blog about the use cases of different routing policies.
Example ServerName shoeasy.me ServerAilas www.shoeasy.me
cd /etc/apache2/sites-available/
nano 000-default.conf
systemctl reload apache2
when you try to log in to the website using yoursite/wp-login.php it again redirects to IPV4. So, let's fix this
login to WordPress -Goto settings, Replace WordPress Address(URL) and Site Address(URL) with your domain name, and Save Changes.
An SSL certificate encrypts the information so that it's not readable until it reaches the server that it's intended for. No one can intercept and read the information as it travels from your computer to the web servers.
apt install certbot python3-certbot-apache
Read the Terms of Service and Type Yes to agree. Provide an email and it will detect your domains simply hit enter to install SSL on all your domain
certbot --apache