In this article, we will host a WordPress website on Virtual Private Server (VPS) using Amazon Lightsail. Before we begin, we must have AWS Free Tier Account and a Registered Domain. There are different ways to host websites on AWS, like Amazon EC2 but Amazon Lightsail is the easiest way to get started for developers who need to launch project quickly.
By the end of this article, we will be able to understand the following:
- Creating Virtual Private Server (VPS) Instance on Amazon Lightsail.
- Creating and assigning Static IP to VPS.
- Configuring WordPress admin panel.
- Creating DNS Zone on VPS.
- Configuring domain provider for AWS nameservers.
- Configuring SSL on Web Server.
Table of Contents
Creating VPS Instance on Amazon Lightsail
What is Amazon Lightsail? When it comes to hosting our website, we have different options: Shared Hosting and Virtual Private Server are two popular type of hosting . Shared hosting is the basic form of hosting which simply means that multiple website share a physical server. Shared hosting is economical and easy to maintain. While on the other hand, we have Virtual Private Server: so-called dedicated server (technically it is still a shared server), it comes with a lot of feature not provided by shared hosting. More feature comes with more price. Without going in to the further details of the two, Amazon Lightsail is used to launch and manage Virtual Private Server.
First of all, we need to sign-in to our Amazon Management Console and search for Lighthsail as shown below:
Once we are on the Lightsail dashboard, click on the “Create Instance” button to get started.
While creating a VPS instance, we will be asked to select Instance Location, Image, Blueprint, and Price Plan.
Picking Instance Location
Lightsail is available worldwide. We can change AWS Region and Availability Zone if we need to. If we are creating multiple instances, AWS suggests launching each instance in a separate availability zone to protect your application from a single point of failure. But in our case, we will leave default values of instance location as we are going to create only one instance in this article.
Picking Instance Image
We will choose Linux OS and an App + OS Blueprint with a development stack preinstalled then we will select WordPress image which is a pre-configured, ready-to-run image for running WordPress on Amazon Lightsail.
Choosing Instance Price Plan
Choosing a price plan for Lightsail is quite flexible. We are free to choose a price plan according to the following: Price per month, Memory, Processing, Storage, and Data Transfer. We will choose $3.50 USD per month which is free for three months (up to 750 hours each month).
Now we need to give a suitable and unique name to our instance to process further. I am leaving the default name as it is.
Click the “Create Instance” button present at the bottom of the page to launch the Instance.
Then we have our newly launched instance on Lighsail. Initially, the state of the instance appears to be Pending, which after a few seconds changes to Running automatically. We can also note that AWS provides us with dynamic IPv4 (22.214.171.124) and IPv6 (2600:1f18:8a5:8c00:ba9f:7536:a7d2:2918) of the newly launched instance.
When we open a browser and request a response from dynamic IP, we will see a WordPress site successfully hosted on the server. Before we do it, make sure that the Instance status has been changed from Pending to Running.
Creating and assigning static Ip to VPS
As we saw that a public dynamic IP was assigned to Lightsail instance but it is not a good practice to continue with dynamic IP. So we need to create a Static IP and assign it to our instance. AWS provides Static IP which is free only while attached to any instance.
To create Static IP, go to the Networking Tab and click on the “Create static IP” button.
Select the Instance which was created earlier from the dropdown and provide a unique name to identify our static IP. Click the “Create” button to proceed further.
Now static IP has been successfully created and assigned to the instance. Note that static IP (126.96.36.199) replaces the previously assigned dynamic IP (188.8.131.52) to our instance.
To verify this, we can open the browser again to request from static IP (184.108.40.206) and we will notice that the WordPress website hosted on the instance. Note that, previously assigned dynamic IP (220.127.116.11) will no longer be working now.
Configuring WordPress Admin Panel
Go to browser and write the following: http://18.104.22.168/wp-login to log in to WordPress admin panel. We can log in using the default username and password. The default username is “user” and to get the default password we need to connect to the instance using SSH by clicking the button highlighted below.
Once an instance connection has been established and you see a command-line tool, write the following commands line-by-line to get a password.
$ ls $ cat bitnami_application_password
You can note the password i.e lykOt1AHLdKK. Now provide credentials to WordPress login to open the admin panel.
We should change the user password immediately after the first login. Now you can do all WordPress stuff like installing themes, modifying content, or installing plugins, etc.
Creating DNS Zone on VPS
If we have registered a domain then we can easily map it to any instance on Lightsail. Earlier, we saw that we opened a WordPress site by requesting static IP on the browser. But if we want to open your hosted website using our own registered domain, then we need to create a DNS Zone on the instance. If we do not have a registered domain, we can purchase it from any domain provider like GoDaddy. We can also purchase a domain from Amazon Route 53.
To create a DNS zone, go to the Networking Tab and click on the “Create DNS zone” button.
Now provide the registered domain name and click on the “Create DNS Zone” button.
After we choose to create DNS Zone, we get a set of AWS nameservers as highlighted in the picture below. Later, we will need to configure/modify our domain provider to use these nameservers.
To route traffic for our domain name to your Lightsail instance, we will add an address (A) record that points your domain name to the static IPv4 address of our instance. To do this, click on the “Add record” and provide/select values as shown below.
Click on the green tick button to add a record and we will see a record added as shown below:
Now we need to add another record of type (A) but with a different sub-domain value (without www). Click on the “Add record” button again and provide the values as shown below:
Now we have two DNS records updated for domain “www.gulraezgulshan.com” and “gulraezgulshan.com” as shown below:
Configuring domain provider for AWS name servers
Since our domain provider is GoDaddy.com, so will log in to our account and select the domain to change its DNS nameservers. Click on the DNS button to process further.
Now we need to update the nameservers as provided by AWS and save the record as shown below. The nameserver record updating may be followed by a confirmation email by GoDaddy. It can take up to 24 hours to propagate changes before we see the response from our domain https://www.gulraezgulshan.com.
Installing SSL Certificate
We will use the Bitnami HTTPS Configuration Tool for configuring HTTPS certificates on the Bitnami stack.
First of all, we need to connect our instance using SSH by clicking on the highlighted button as shown below.
It will open an SSH command-line connection to our instance as shown below:
Now, write the command below to get started with the Bitnami HTTPS configuration tool.
This tool will prompt a few details to configure HTTPS. Below are the answers to all questions that the tool will prompt.
Please provide a valid space-separated list of domains for which you wish to configure your web server: gulraezgulshan.com
The following domains were not included: www.gulraezgulshan.com. Do you want to add them? [Y/n] : Y
Enable HTTP to HTTPS redirection [Y/n] : Y
Enable non-www to www redirection [Y/n]: Y
Enable www to non-www redirection [Y/n]: N
Do you agree to these changes? [Y/n]: Y
Email address: email@example.com
Do you agree to the Let's Encrypt Subscriber Agreement? [Y/n]: Y
In the end, you will see a success message showing that Bitnami HTTPS Configuration Tool succeeded in modifying your installation.
Now when you will open your browser and type gulraezgulshan.com, you will see that your connection is secured with HTTPS configured.
SSH to Lightsail, Opening PHYMyAdmin
We may need to open SSH connection to the remote instance using client software like PuTTy and open PHYMyAdmin to view database details of our hosted WordPress website. Read the SSH and Connecting to Amazon Lightsail Instance to achieve this.