Launch Your WordPress website with AWS Lightsail with few clicks only!
Tags: beginners, aws, wordpress
Published: 2020-12-26 00:29:29

Lightsail is an amazing service by AWS. It's beginner-friendly and someone who is new to AWS should begin with it to get the hang of it. It offers Virtual servers, storage, databases, and networking for a low and easy-to-understand prices. Lightsail also supports Load balancers, CDN and containers now!

In this tutorial, I am going to show you how easy it is to launch your WordPress website on AWS Lightsail with SSL and your domain.

#### Step 1: Launch WordPress Instance
From the AWS console, go to Lightsail. Once on the AWS Lightsail homepage, click "Create Instance"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rgu3fx69cwsr0vmqghgj.png)

Select region (closest to your targeted audience)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y42nvf3rwmvw1akp0k4d.png)

Select "WordPress" as your instance image
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dyhjunyct6ken5a0840n.png)

Click "Change SSH key pair"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9akzfh1a9xnv92m8n2yf.png)

Make sure you have downloaded the SSH key (we will need this later on) before proceeding. If you don't like the default one you can create a new one using "Create New". Leave "Enable Automatic Snapshots" for now, we will cover snapshot later on
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/71g4eup2iiyguk3ykofv.png)

Give any name to uniquely identify your instance, leave the number of instances to 1, choose the pricing plan that's suitable for you, and click "Create Instance"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/71g4eup2iiyguk3ykofv.png)

Once you launch the instance, it will take some time to boot. Once the instance is booted up, you can copy the IP address and paste it into a new browser tab to access your website
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1y8hkrmjly6tsng1c9j5.png)

If you enter the IP address in the browser tab you will notice that it has installed WordPress with the latest default theme - [twenty twenty one](https://wordpress.org/themes/twentytwentyone/) (at the time of writing)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4ct7cjbwtbp1gylvjev5.png)

🎉 Congratulations! You have launched your own WordPress website. Let's attach an SSL certificate and domain to it and get admin credentials.

-----

#### Step 2: Attach domain
From the AWS Lightsail dashboard, click on the newly created instance name
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/259wl92xlftavptf6lw6.png)

Select "Networking"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ddcnir0ml0xcpuhp09ss.png)

Click "Create static IP"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/43jxshzxfnvxud5rp8ae.png)

From the "Attach to an instance" dropdown, select the newly created instance. GIve any Name and click "Create"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/90vfk3li30izazab5bzm.png)

This will attach a static IP to your instance (WHich essentially means that your IP will be the same even after you restart your instance). Your website will only be accessible with the new IP now (not the previous one). After the static IP has been created and attached it will show you the IP details page. Click on the AWS Lightsail logo from the top left corner to go back to the AWS Lightsail dashboard
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9y2d6khifmyhjrhqpaxt.png)

Now go to your domain registrar's control panel and add a new `A-record` against your domain. Set the value equal to the new (static, the one we created earlier) IP
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mbf3w76wjbyp56m66v1r.png)

_I am using AWS Route 53, but the setup is pretty much the same for every domain registrar (GoDaddy, Namecheap, Dreamhost, Hostgator, etc.)_

You should be able to access your website using your domain now. Please note that it can take up to 72 hours to complete DNS propagation, so don't worry if you are not able to access your website using the domain name right away.

----
#### Step 3: Generate an SSL certificate
The next step is to generate and attach an SSL certificate. For that connect to your website using SSH by the following command
`ssh -i <path_to_your_key> bitnami@<your-domain-or-ip>`
When prompted for adding to the known host list, type `yes` and press enter
If it says something about bad permissions then run the following command to change the key file permissions
`sudo chmod 400 <path_to_your_key>`
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/blnwlql62exgyrzbr4f1.png)

Once you have logged in to your instance (via ssh), run the following command
`sudo /opt/bitnami/bncert-tool`

It will ask you a series of questions. Enter in the domain name you are using (add www version too if you intend to use it). Type `Y` and press enter when it asks for "Enable HTTP to HTTPS redirection", and "Do you agree to these changes?". Enter in your email address, again type `Y` and press enter when it asks "Do you agree to the Let's Encrypt Subscriber Agreement?"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8zivs0uf7j6xh34lola5.png)

After that, you should be able to access your website with `https`
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ddnara0475nez2q241sx.png)

----

#### Step 4: Get admin credentials
Let's first remove the bitnami default page link from the bottom right corner 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pm6d7k8s56tk8al24h7p.png)

While being logged in to your instance (via ssh), run
`sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1`

To get the credentials, run the following command:
`cat ~/bitnami_credentials`
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/eqybs1lrl6nuz51j3jg9.png)

Now go to `https://<your_domain_here>/wp-admin` and you should be able to login to the WordPress dashboard using the user/password we got earlier
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xiykrywjwvub3cwo1smb.png)

-----
#### Extras:
- We used [Let's Encrypt Free SSL](https://letsencrypt.org/) and [Lego Client](https://github.com/go-acme/lego) behind the scenes to generate a free SSL and then set-up a [`cron` job](https://en.wikipedia.org/wiki/Cron) to renew the SSL certificate automatically when it expires
- In AWS Lightsail you can take snapshots (full-fledged cloned images of your instance) by going to the Instance page and then selecting the snapshot tab. Using snapshots you can take backups, keep older versions of your website or you can create larger size (upgraded) instances. The AWS Lightsail snapshots are pretty cheap, you can [check the prices here](https://aws.amazon.com/lightsail/faq/#:~:text=Q%3A%20What%20do%20Lightsail%20snapshots,the%20end%20of%20the%20month.) 
- It's a simple option and works really well, I am using AWS Lightsail for hosting my small baby clothes store: 🍼 [Toddos Club](https://toddosclub.com/)