Deploy WordPress App to Amazon Lightsail
Tags: aws, lightsail, wordpress, beginners
Published: 2022-05-08 11:02:48

## 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](https://portal.aws.amazon.com/billing/signup). Before starting to deploy your app read about [Amazon Lightsail Pricing and Free-Tier](https://aws.amazon.com/lightsail/pricing/). 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](https://lightsail.aws.amazon.com). You should see a page like this:

![CleanShot 2022-04-27 at 17.59.20@2x.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651060787414/7TgXRwaI1.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651061181136/t7Kzr_AGl.png)

2. Let's choose **Instance location**, **platform**, and **blueprint**:
![CleanShot 2022-04-27 at 18.20.07@2x.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651064483874/SsoaPiAKt.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651065101157/8eZaPa-e5.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651065976006/xngXQF1qF.png)

After Stop and Start the instance, it got a new Public IP address: 
![CleanShot 2022-04-27 at 19.31.30@2x.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651066336570/qlxGqkjSB.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651066765698/qL0v8VIuH.png)
3. Add a meaningful name and click Create:
![CleanShot 2022-04-27 at 19.42.36@2x.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651067026152/wMDiRyzMD.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651068506979/ofhpf4_1M.png)

#### Using SSH Client
1. Download the SSH key from here: 
![CleanShot 2022-04-27 at 20.10.12@2x.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651068654032/OKPX9IZfO.png)
2. If you are using PuTTY you can [follow this tutorial](https://lightsail.aws.amazon.com/ls/docs/en_us/articles/lightsail-how-to-set-up-putty-to-connect-using-ssh). 
3. If you are using a terminal in macOS or Linux, run this command on where you downloaded the SSH key. 

```bash
# 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>

``` 


### 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
```bash
cat bitnami_application_password
```
![CleanShot 2022-04-27 at 20.23.35@2x.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1651069453965/Ehgt_JWU7.png)
3. 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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651100514891/POkz7myRi.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651100878512/fz1N3wW4u.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651101055794/Y_EVt8m18.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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651101295885/pp15TFvIg.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: 
```bash
cat stack/wordpress/wp-config.php
```
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](https://cdn.hashnode.com/res/hashnode/image/upload/v1651070563015/vdJ8wmLh2.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:
```bash
sudo apt-get install git
```
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.