DEV Community

loading...

Launch Your WordPress website with AWS Lightsail with few clicks only!

Mubbashir Mustafa
Hi, I am Mubbashir. I specialize in developing highly scalable & distributed web apps. I help startups in developing their apps & ideas. Here I usually write about Microservices, DevOps, AWS and React
・5 min read

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

Select region (closest to your targeted audience)
Alt Text

Select "WordPress" as your instance image
Alt Text

Click "Change SSH key pair"
Alt Text

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

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

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

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 (at the time of writing)
Alt Text

🎉 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

Select "Networking"
Alt Text

Click "Create static IP"
Alt Text

From the "Attach to an instance" dropdown, select the newly created instance. GIve any Name and click "Create"
Alt Text

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

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

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

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

After that, you should be able to access your website with https
Alt Text


Step 4: Get admin credentials

Let's first remove the bitnami default page link from the bottom right corner
Alt Text

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

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


Extras:

  • We used Let's Encrypt Free SSL and Lego Client behind the scenes to generate a free SSL and then set-up a cron job 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
  • It's a simple option and works really well, I am using AWS Lightsail for hosting my small baby clothes store: 🍼 Toddos Club

Discussion (0)