DEV Community

Cover image for Deploy WordPress App to Amazon Lightsail
Harun R Rayhan for AWS Community Builders

Posted on • Originally published at blog.harun.dev

Deploy WordPress App to Amazon Lightsail

Introduction

AWS Lightsail can be the easiest entry to the AWS Cloud. It has fixed monthly pricing unlike most other services, so you don't have to worry about a huge monthly bill.

Lightsail is really great for small to medium apps. It has out-of-the-box support for WordPress, Magento, Joomla, Prestashop, Drupal, Ghost, and Django apps.

It provides pre-configured stacks like LAMP, NGINX, MEAN, and Node.js. You can also launch pre-configured Plesk, WHM & cPanel in just a few clicks.

But that's not all. You can launch any Linux-based and Windows OS instance. My personal favorites are Ubuntu and Amazon Linux 2.

Prerequisites

Need a valid AWS account to deploy the WP app. If you don't have one, just create one from here. Before starting to deploy your app read about Amazon Lightsail Pricing and Free-Tier. Don't worry, I will try to keep everything within the free tier. At this time of writing, you can run a Lightsail instance for free for 3 months.

Install WordPress App

Login to your AWS account if not already. Go to Lightsail homepage. You should see a page like this:

CleanShot 2022-04-27 at 17.59.20@2x.png

Are you seeing this? Let's go 🏃‍♂️

Create Instance

  1. Now click on the big Create Instance button. If you don't see one, follow this:
    CleanShot 2022-04-27 at 18.04.31@2x.png

  2. Let's choose Instance location, platform, and blueprint:
    CleanShot 2022-04-27 at 18.20.07@2x.png
    A. Click the link to change location and availability zone (AZ) if not what you want. I recommend selecting a location closer to your customers.
    B. Choose the Linux/Unix platform.
    C. Select the Apps + OS from the blueprint.
    D. Now choose WordPress from the app list. Not the multisite one.

  3. Now scroll down to Choose your instance plan section. I chose a free-tier plan and only one instance. Here is my setup:
    CleanShot 2022-04-27 at 19.04.37@2x.png

  4. Finally scroll to the bottom of the page and click the Create instance button. Wait for the status to become Running. Congratulations, your instance has launched 🚀

Assign a Static IP (optional)

AWS Lightsail Instance comes with public (and private) IP. Which changes every time Stop and Start the instance. My Public IP was this when I launched the instance:
CleanShot 2022-04-27 at 19.24.43@2x.png

After Stop and Start the instance, it got a new Public IP address:
CleanShot 2022-04-27 at 19.31.30@2x.png

We have to fix that. So, let's create and assign a Static IP:

  1. Click on your application instance name to see the details of your instance.
  2. Click on + Create static IP from here: CleanShot 2022-04-27 at 19.35.25@2x.png
  3. Add a meaningful name and click Create: CleanShot 2022-04-27 at 19.42.36@2x.png > ⚠️ Warning: You are allowed to assign 5 static IPs for free. You will be charged for static IP that is not attached to a running instance.

Connect to the instance using SSH

You can connect to an instance in two ways:

Using browser

That's the easiest. Go to the Connect tab and click Connect using SSH:
CleanShot 2022-04-27 at 20.07.41@2x.png

Using SSH Client

  1. Download the SSH key from here: CleanShot 2022-04-27 at 20.10.12@2x.png
  2. If you are using PuTTY you can follow this tutorial.
  3. If you are using a terminal in macOS or Linux, run this command on where you downloaded the SSH key.
# Run for the first time to fix the permission
chmod 400 <path/to/your-lightsail-ssh-key>.pem

# Connect to your Lightsail instance
# Username and Public IP can be found in "Connect" tab
ssh -i "<path/to/your-lightsail-key>.pem" <username>@<public_ip>

Enter fullscreen mode Exit fullscreen mode

Get Admin Username and Password

  1. You can get the username from the Connect tab. The username is user for this stack.
  2. To get the password, log in to SSH and run this command
cat bitnami_application_password
Enter fullscreen mode Exit fullscreen mode

CleanShot 2022-04-27 at 20.23.35@2x.png

  1. Now open a browser tab and go to http://<public_ip>/wp-admin. Enter username and password above. You should see the WP Admin dashboard like me.

Add a Domain

  1. Go to the Home page. Click on the Networking tab and then hit Create DNS zone button CleanShot 2022-04-28 at 04.57.42@2x.png
  2. Add your domain name. Scroll to the bottom and click the Create DNS zone button CleanShot 2022-04-28 at 05.03.10@2x.png
  3. Add these name server records in your domain control panel (ex. Namecheap, GoDaddy). You might have different records than mine CleanShot 2022-04-28 at 05.09.00@2x.png
  4. Now to the good part. Click + Add Record button. Add your instance and click on tick icon to save. CleanShot 2022-04-28 at 05.13.07@2x.png > ⚠️ It may take few minutes to days to propagate DNS records.
  5. Now update the domain name in siteurl and home rows of wp_options table.

Import Existing App

Import Database

You may have an existing database. You can import your database to the Lightsail instance. You can use a Database client app like TablePlus, MySQL Workbench, or even just the terminal.

Your database credentials exist in wp-config.php file. Connect to your instance via SSH and run this command:

cat stack/wordpress/wp-config.php
Enter fullscreen mode Exit fullscreen mode

Use DB credentials to connect to DB, and replace localhost with the instance's public IP. Connect to your DB via SSH (recommended) or add the 3306 port here:
CleanShot 2022-04-27 at 20.40.01@2x.png

ℹ️ Don't forget to change the domain name in siteurl and home rows of wp_options table.

Import existing files

Application folder located in stack/wordpress. You can upload files in two ways:

  1. SFTP Client: You can use SFTP clients like FileZilla or Transmit to upload files. Use the same SSH credential to upload files.
  2. Git: Connect to your instance via SSH. Install git by using this command:
sudo apt-get install git
Enter fullscreen mode Exit fullscreen mode

Now pull your files from git using the git clone/pull command.

Conclusion

This is just the first step toward deploying your WordPress app to Amazon Lightsail instance. There are lot more you can do. You are welcome to ask your questions, give me feedback, or any improvement request.

Top comments (3)

Collapse
 
mhasan profile image
Mahmudul Hasan • Edited

Vai I faced this issue when I going to AWS Lightsail homepage, I think I have credit card issue.
Image

I have also face this issue
Images

Do I need to wait?

Collapse
 
harunrrayhan profile image
Harun R Rayhan

Probably they need some more info, just click first link from the first image. If problem still persist, contact support. Hope they will help you.

Collapse
 
iamrashedxaman profile image
Rashed Zaman

Very interesting to know that in detail. Thank you very much bro.