In my previous post I explained how to deploy a simple WordPress site using AWS. This post shows how to set up a custom domain to access your site. The default way to access EC2 instances is by typing its IP address (192.168.0.1) in a browser. This is great for testing, but when going public with your blog or portfolio website, it makes more sense to have a domain name such as "example.com" instead. You can learn more about DNS and IP addresses outside this post.
AWS Route53 is a web-based domain resolution service, packed with additional features for reliability and scalability. It's easy to use, flexible and great for beginners. However, this post is intended for those (like me) who do not wish to use Route53.
Navigate to EC2 > Network and Security > Elastic IPs on the AWS Management Console and click on allocate new address.
Click "Allocate" on the next screen. You'll see your newly created Elastic IP after confirming. Select this IP > Actions > Associate Address.
Select your instance from the dropdown and click Associate. You now have an elastic IP address for your EC2 instance. This means you have a static IP that doesn't change even after restarting the instance. This is important to complete our next step.
Verify that you can see your website by navigating to this elastic IP address.
Create type A DNS record for your domain, which points to your elastic IP. Without an elastic IP, we'd have to keep updating this record ever time you restart your AWS instance.
After you create a new DNS record it can take anywhere between 5 minutes to 1 hour, to update. ⏳
Login to your EC2 instance via SSH, then specify your domain name in apps/wordpress/htdocs/wp-config.php file like shown below.
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');
And that's about it. You should be able to access your WordPress site at your domain address. 🎉
Let me know what you thought about this article in the comments. I want to improve my writing and help others learn to love tech, the way I did.