There are a huge number of WordPress hosting providers out there. Even WordPress does hosting on wordpress.com. There are pros and cons to using these hosting providers vs hosting it yourself. I will leave it up to you as to whether or not you should pay someone else to host your WordPress site, or if you should do it yourself. Today we will focus on how you can use Amazon Web Services (AWS) to host your WordPress site with minimal effort to get the site up and running.
What is EC2 and What is Lightsail?
Elastic Compute Cloud or EC2 for short was one of the first products available on AWS. It allows you to easily and somewhat cheaply run virtual machines on public cloud infrastructure. In short, you can rent Amazon’s servers to run your own virtual machines. This saves you the time and effort of building and operating the physical servers in a physical datacenter. It also gives you the option to rapidly increase or decrease the number of machines you are running at the drop of a hat.
The problem with EC2 instances and WordPress is predictability. You don’t know what exactly your cost is going to be. You are paying by the hour for your CPU, you have to pay for the IP addresses, for the DNS zones, for the bandwidth, etc… Add this up and you might get bills that are higher than you were anticipating. This is where Amazon Lightsail comes in.
Lightsail is similar to EC2 in that it is used for running VM’s. But the great part about EC2 is it is cheaper per instance to run. And it is a fixed monthly cost. So you don’t have to worry about unexpected charges. This cost includes a good amount of bandwidth, IP address, DNS, compute instance, etc…
Below we can see the pricing of Lightsail and the instances sizes they correspond to as of the time I am writing this article. As you can see the cheapest instance is $ 3.50. And we can double the memory for another $1.50/month. You can see the current pricing for Lightsail here.
Next, we can look at the pricing for EC2. The pricing for EC2 is not as straightforward and does not fit in a simple screenshot. For that reason, you will want to spend some time with the pricing calculator. Here is a screenshot from the pricing calculator that shows what an instance might cost.
In the above screenshot, you can see that a t2.micro instance costs $8.50 per month. If we do a 3-year commitment and pay for the whole thing up front, we can get the price all the way down to $3.65/month. That is quite the savings. But is it as cheap as Lightsail? We don’t really know until we know what a t2.micro instance is. To look at was the different instance types are, look here. On this page
In the above excerpt, you can see the t2.nano specs match what we were seeing in the $3.50 plan on Lightsail, and the t2.micro matches the $5 version. Based on the pages above, if we are going to pre-pay for at least a year, we can get the cost of the EC2 instances down below the cost of the Lightsail instances. However, compute cost is only part of the overall cost.
When using EC2 instances, you have to also pay for DNS, Bandwidth, etc… So you don’t really know what your costs will be until you get your bill. All these items are included in Lightsail. So you know upfront what your costs will be. But they won’t necessarily be lower.
How to deploy a Lightsail instance
To deploy your Lightsail image, we first need to visit the AWS console. If you don’t already have an account, you can signup here. Once you are in, Click on the services menu, then click Ligthsail located under compute:
This will open a new tab, and take you over to the Lightsail console. First thing you should do is add an SSH key to your account so you will be able to SSH into the instances you will be creating.
Click on the Account button in the top right corner, then click on account again. Next click on the SSH keys tab. At this point, you will have two options. You can click on the Create New button to create a new SSH keypair. If you do this, it will store the .pub file on the server for you and prompt you to download the private key file. You will want to store this private key in the .ssh folder in your user home folder. The second option is to click on Upload New.
If you choose to upload a new key, and you are on Linux or MacOS, open a terminal and type ssh-keygen and it will generate an SSH keypair for you. and store it in your .ssh folder. You can then upload the .pub file and you are set with your SSH keys. Click on the Home button at the top of the screen to take you back to the main console for Lightsail.
To start the process of creating the VM, you just have to click the Create Instance button. After you click that, you will be put into a wizard to create your VM. The following two screenshots show pretty much the whole process.
First, you select the region to run your instance in. Lightsail does not have as many region options as EC2. But there are 3 regions in the United States. Next, you select if you want to deploy on Windows or Linux. And finally, you select the blueprint you want. You can get an instance with nothing on it. Or you can get it with applications like WordPress pre-loaded onto the image.
After you select the type of machine you are deploying, you need to select your instance size. After you select your instance size, give your new machine a name, or accept the defaults and click on Create Instance
Your machine will now be created. You will be redirected back to the home screen, and you should see a machine marked as pending as it is being created.
Even after the machine goes from Pending on online, you should still give the machine a minute or two before connecting to it. When it is in a pending state the machine is doing all the cloning and setup options. When it goes online, It means the machine is finished getting built. But it still needs to do the initial boot.
To connect to your instance you have two options. You can click on the orange button in the top right corner of the instance within the Lightsail console. Or you can SSH to the IP address listed in the bottom right corner. If you use SSH, you will need your SSH key all set up. You will need to use the username bitnami when connecting to the machine via SSH.
Here is what it looks like when you connect via the browser window
At this point, our WordPress site is set up and ready to login to. The problem is we don’t know the password to our WordPress site. Lucky for us, Bitnami has hidden the password on the new instance for us. To find the password, open the web console or SSh window, then run the following command:
This will output the username and password to login to your WordPress site:
Now that we have the username and password, you can type the IP address of your instance into your web browser, then login to the WordPress site and start customizing it.
A few things that are still left, but we will cover in a future article. You don’t yet have HTTPS on your blog. It is always a good idea to enable HTTPS on all of your websites. There are a few options for this, but my favorite one is to use letsencrypt. Bitnami has instructions for setting up letsencrypt with a bitnami application.
The next consideration is CDN. This tiny WordPress site won’t be able to handle a whole lot of direct traffic. For this reason, you really need a CDN. You have various options through various providers, including Amazon. However, Amazon’s offering is not free. There is a free tier of Cloudflare which will not only give you DNS hosting, and access to a CDN. But they will also handle the HTTPS side of things for you. This wouldn’t be complete encryption through the entire path. But it would greatly reduce the risk of someone snooping on the traffic while it is in route.
Thank you for joining us today. We were able to discuss what Lightsail is, what EC2 is, now they are similar, and how they are different. We then deployed a WordPress site using Bitnami templates on AWS. And confirmed with could log in to the new WordPress site.