Software Developer, Technology Enthusiast, Retro and Husband and Dad based in Melbourne.

Wordpress

AWS Lightsail Docker Volume

Summary

This guide shows you how to attach an AWS Lightsail block storage disk to an Ubuntu instance, format and mount it at /data, and configure Docker so its named volumes live on that disk. This keeps your WordPress and database data on the larger block storage volume and ensures it persists across reboots (and can survive instance rebuilds if you reattach the disk).

1. Confirm your Region and Availability Zone

Before you create the disk, you need the instance’s Availability Zone (AZ). The AWS Lightsail create-disk command won’t work unless you provide –availability-zone.

  • lightsail-instance-config.json: Get the Availability Zone from the lightsail-instance-config.json file created in Lightsail Instance for Docker
  • AWS CLI (pull the AZ directly from Lightsail):
aws lightsail get-instances --query "instances[?name=='MyUbuntuInstance'].location.availabilityZone | [0]" --output text --profile MyUbuntuProfile

Options explained

  • aws lightsail get-instances This command tells the AWS CLI to return details for all instances in the account/region tied to the selected profile.
  • --query "instances[?name=='MyUbuntuInstance'].location.availabilityZone | [0]" AWS CLI User Guide – Filtering output with –query.
  • --output text Prints the result as plain text.
  • --profile MyUbuntuProfile Selects which AWS CLI profile to use. This is helpful if you have multiple accounts or credentials configured.

2. Create the Lightsail disk

Create a new Lightsail block storage disk using the aws lightsail aws lightsail create-disk command, and provisioning in the same Availability Zone as your existing instance.

aws lightsail create-disk --disk-name MyUbuntuProfile-Docker-Volume-1 --region ap-southeast-2a --size-in-gb 32 --profile MyUbuntuProfile

Options explained

  • aws lightsail create-disk This command tells the AWS CLI to create a new block storage disk.
  • --disk-name MyUbuntuProfile-Docker-Volume-1 Choose a unique and descriptive name for the disk in your Lightsail account.
  • --region ap-southeast-2a Despite the flag name, Lightsail expects the AZ for block storage here (e.g., ap-southeast-2a).
  • --size-in-gb 32 Disk size. You choose based on WordPress + DB growth, uploads, backups, etc.
  • --profile MyUbuntuProfile Selects which AWS CLI profile to use. This is helpful if you have multiple accounts or credentials configured.

3. Attach the disk to your instance

Now that the disk is created MyUbuntuProfile-Docker-Volume-1, attach it to the instance MyUbuntuInstance so Ubuntu can detect it as a new drive.

aws lightsail attach-disk --disk-name MyUbuntuProfile-Docker-Volume-1 --disk-path /dev/xvdf --instance-name MyUbuntuInstance --profile MyUbuntuProfile

Options explained

  • aws lightsail attach-disk This command tells the AWS CLI to attach a block storage disk to an instance.
  • --disk-name MyUbuntuProfile-Docker-Volume-1 The name of the Lightsail disk you created earlier. This must match exactly.
  • --disk-path /dev/xvdf Device name Ubuntu will see for the newly attached disk in Ubuntu instance. This is the attachment path; in Ubuntu, it may appear as /dev/xvdf or sometimes /dev/nvme, depending on the virtualization.
  • --instance-name MyUbuntuInstance Instance name you’re attaching the disk to.
  • --profile MyUbuntuProfile Selects which AWS CLI profile to use. This is helpful if you have multiple accounts or credentials configured.

4. Verify attachment

Now let’s confirm the command returns a quick status summary for the Lightsail block storage disk.

aws lightsail get-disk --disk-name MyUbuntuProfile-Docker-Volume-1 --query 'disk.{name:name,state:state,attachedTo:attachedTo,path:path,isAttached:isAttached}' --output table --profile MyUbuntuProfile

Options explained

  • aws lightsail get-disk This command tells the AWS CLI to retrieve details about one block storage disk.
  • --disk-name MyUbuntuProfile-Docker-Volume-1 Which disk to look up in Lightsail disk resource.
  • --query 'disk.{name:name,state:state,attachedTo:attachedTo,path:path,isAttached:isAttached}' Using a JMESPath query extracting from the top-level disk object.
  • --output table Render the result as a human-readable ASCII table – Setting the output format in the AWS CLI
  • --profile MyUbuntuProfile Selects which AWS CLI profile to use. This is helpful if you have multiple accounts or credentials configured.

Output

-----------------------------------------------------------------
|                            GetDisk                            |
+------------+--------------------------------------------------+
|  attachedTo|  MyUbuntuProfile-Docker-Volume-1-docker-1        |
|  isAttached|  True                                            |
|  name      |  MyUbuntuProfile-Docker-Volume-1                 |
|  path      |  /dev/xvdf                                       |
|  state     |  in-use                                          |
+------------+--------------------------------------------------+

5. Connect to the Ubuntu instance via SSH

Next, connect to the Lightsail instance via SSH so we can format and mount the disk on the Ubuntu server.

ssh MyUbuntuInstance

6. Identify the new disk in the Ubuntu Instance

Next, we need to identify the disk that will be mounted on the system.

sudo lsblk

Options explained

  • sudo Run the command with administrator privileges.
  • lsblk Run the command to display all disks, partitions, and mount points currently available on the Ubuntu server.

Output

NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS

nvme1n1      259:5    0   32G  0 disk

7. Create a filesystem on the new disk (only if empty)

Next we need to format the disk /dev/nvme1n1 with the XFS filesystem.

sudo mkfs -t xfs /dev/nvme1n1

Options explained

  • sudo Run the Linux command with administrator privileges.
  • mkfs Is the Linux command make filesystem, create a new filesystem on the target disk.
  • -t xfs Create the disk using the XFS filesystem type.
  • /dev/nvme1n1 Disk device being formatted.

Output

meta-data=/dev/nvme1n1           isize=512    agcount=16, agsize=524288 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=1
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=8388608, imaxpct=25
         =                       sunit=1      swidth=1 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

8. Create a mount point (folder) and mount the disk

First, create a folder that will be used as the disk’s mount location.

sudo mkdir -p /data

Next, mount the disk to that folder.

sudo mount /dev/nvme1n1 /data

Options explained

  • sudo Run the command with administrator privileges.
  • mount Is the Linux command used to attach a storage device to the filesystem.
  • /dev/nvme1n1 is the block device representing the disk that was identified.
  • /data This is the folder where the disk will be accessible and mounted.

Finally, confirm that the disk is mounted successfully using df utility command.

df -h | grep /data

Options explained

  • df Shows disk usage and mounted filesystems.
  • -h Displays sizes in GB, MB, etc.
  • grep /data Filters the output to show only the /data mount.

This mount is temporary and will disappear after a reboot. In the next step, the disk will be added to /etc/fstab so it automatically mounts when the server starts.

9. Persist the mount using /etc/fstab on reboot

Before modifying the filesystem table, it is recommended to create a backup of the file. If an error is introduced while editing /etc/fstab, the system may fail to mount disks correctly during startup.

sudo cp /etc/fstab /etc/fstab.orig

We need to use the UUID (Universally Unique Identifier) of the disk instead of the device name.
This is more reliable because device names like /dev/nvme1n1 can sometimes change after reboot.

sudo blkid /dev/nvme1n1 

Options explained

  • sudo Run the command with administrator privileges.
  • blkid Utility command that shows block device attributes, such as UUID , filesystem type and label.
  • /dev/nvme1n1 Block device representing the disk.

Output

/dev/nvme1n1: UUID="92a4a81e-d66f-420e-9f7a-234cbb5c681e" BLOCK_SIZE="512" TYPE="xfs"

Open the filesystem table configuration file, this file controls which disks are mounted automatically when the system boots.

sudo nano /etc/fstab

Add the following line to the bottom of the file, please tab.

UUID=92a4a81e-d66f-420e-9f7a-234cbb5c681e  /data  xfs   defaults,nofail  0  2

Options explained

  • UUID=92a4a81e-d66f-420e-9f7a-234cbb5c681e Unique identifier for the disk.
  • /data Folder where the disk will be mounted and made accessible.
  • xfs Filesystem type used when the disk was formatted.
  • defaults,nofail Standard mount options. nofail prevents boot errors if the disk is missing.
  • 0 Dump backup option, which is typically set to 0 to disable filesystem backups.
  • 2 Order for filesystem checks during boot.

10. Reboot test

Restart the server to confirm the disk mounted /data automatically.

sudo reboot

Next, reconnect to the Lightsail instance via SSH.

ssh MyUbuntuInstance

Finally, run the df command to confirm the disk is mounted successfully.

df -h | grep /data

Output

/dev/nvme1n1      32G  660M   32G   3% /data

11. Adding Docker Volume

We need to ensure Docker starts after /data is mounted. it is important that /data is available before Docker starts.

If Docker starts before /data is mounted during system boot, it may create empty directories under /data. This can cause containers to start with missing or incorrect data.

To prevent this issue, add a dependency so Docker waits until /data is mounted before starting.

Connect to the Lightsail instance via SSH.

ssh MyUbuntuInstance

Create a systemd override for Docker, this opens a small override file.

sudo systemctl edit docker

Add the dependency. This tells systemd that Docker must wait until the /data mount is available before starting.

[Unit]
RequiresMountsFor=/data

Reload systemd and restart Docker or reboot.

sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl restart docker

Or.

sudo reboot

12. Preparing Docker Volumes for WordPress for Lightsail

Create the folders under /data that will hold the persistent data for the WordPress files and MySQL database. Docker will later bind the named volumes to these locations.

Create the folders on /data that will hold the Docker volume data.

sudo mkdir -p /data/volumes/wp_html
sudo mkdir -p /data/volumes/mysql

Create named Docker volumes backed by those folders on /data.

docker -H ssh://MyUbuntuInstance volume create wp_html --driver local --opt type=none --opt device=/data/volumes/wp_html --opt o=bind
docker -H ssh://MyUbuntuInstance volume create mysql_data --driver local --opt type=none --opt device=/data/volumes/mysql --opt o=bind

Options explained

  • docker volume create creates a new Docker volume, wp_html and mysql_data are the names of the volumes.
  • --driver local tells Docker to use the local volume driver.
  • --opt type=none is used when creating a bind-backed volume.
  • --opt device=... points Docker to the folder on your machine.
  • --opt o=bind tells Docker to bind that folder into the volume.

Verify Volumes

Check that Docker is using your local folders.

docker -H ssh://MyUbuntuInstance volume inspect wp_html

Output

Docker will return JSON output describing each volume.

[
    {
        "CreatedAt": "2025-12-16T11:14:48Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/wp_html/_data",
        "Name": "wp_html",
        "Options": {
            "device": "/data/volumes/wp_html",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]
docker volume inspect mysql_data

Output

[
    {
        "CreatedAt": "2025-12-16T11:16:01Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/mysql_data/_data",
        "Name": "mysql_data",
        "Options": {
            "device": "/data/volumes/mysql",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]

Further Reading

Using WordPress on AWS Lightsail and Docker

Docker Desktop volumes for WordPress

Summary

This chapter explains how to create persistent Docker Desktop volumes for WordPress and MySQL using local folders on Windows, macOS, and Linux.
Docker Desktop manages the volumes while allowing the data to remain accessible on your local machine. This ensures that your WordPress files and database data are retained when containers are stopped, removed, or recreated.
In the next chapter, you will learn how this approach differs from using AWS block storage and manually mounted volumes on an AWS Lightsail instance.

1. Create Local Folders for Data

Choose a location on your computer where Docker will store persistent WordPress and MySQL data.

Windows

mkdir C:\docker-data\wp_html
mkdir C:\docker-data\mysql
Output
  • C:\docker-data\wp_html for WordPress files
  • C:\docker-data\mysql for MySQL database files

macOS / Linux

mkdir -p ~/docker-data/wp_html
mkdir -p ~/docker-data/mysql
Output
  • ~/docker-data/wp_html for WordPress files
  • ~/docker-data/mysql for MySQL database files

2. Create Bind-Backed Docker Volumes

Create named Docker volumes that bind to the local folders you created earlier. This allows Docker to store WordPress and database data in those folders instead of inside Docker’s default internal storage.

Windows

docker volume create wp_html --driver local --opt type=none --opt device=C:\docker-data\wp_html --opt o=bind
docker volume create mysql_data --driver local --opt type=none --opt device=C:\docker-data\mysql --opt o=bind

macOS / Linux

docker volume create wp_html --driver local --opt type=none --opt device=$HOME/docker-data/wp_html --opt o=bind
docker volume create mysql_data --driver local --opt type=none --opt device=$HOME/docker-data/mysql_data --opt o=bind

Options explained

  • docker volume creates a new Docker volume. In this example, wp_html and mysql_data are the names of the volumes being created.
  • --driver local tells Docker to use the local volume driver.
  • --opt type=none is used when creating a bind-backed volume.
  • --opt device=... tells Docker which folder on your machine should be used for the volume.
  • --opt o=bind tells Docker to bind that folder into the volume.

3. Verify the Docker Volumes

Check that Docker is using the local folders you mapped.

docker volume inspect wp_html

Output

Docker will return JSON describing the volume configuration.

[
    {
        "CreatedAt": "2026-03-17T12:01:21Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/wp_html/_data",
        "Name": "wp_html",
        "Options": {
            "device": "C:\\docker-data\\wp_html",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]
docker volume inspect mysql_data

Output

[
    {
        "CreatedAt": "2026-03-17T12:00:51Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/mysql_data/_data",
        "Name": "mysql_data",
        "Options": {
            "device": "C:\\docker-data\\mysql",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]

4. Start Your Containers Using the Volumes

After the volumes have been created, they can be attached to your WordPress and database containers. When the containers use wp_html and mysql_data, Docker stores the data in the local folders you configured earlier rather than in Docker’s default internal storage.

A typical setup maps

wp_html -> /var/www/html
mysql_data -> /var/lib/mysql

You can then start your containers with Docker Compose, depending on how your project is structured. Because the data is stored outside the containers, it remains available even if the containers are stopped, removed, or recreated.

This gives you a straightforward Docker Desktop development setup with persistent storage. WordPress files remain available between container restarts, MySQL data is retained even if containers are rebuilt, and the files stay accessible from the host machine. Another advantage is that no manual disk formatting or mounting is required.

Because this approach works across Windows, macOS, and Linux with Docker Desktop, it is well suited to local WordPress development, plugin testing, theme experimentation, or preparing an application before deploying it to a cloud server.

Further Reading

Using WordPress on AWS Lightsail and Docker

AWS Lightsail Instance for Docker

Summary

This chapter guides you through setting up an Ubuntu Lightsail instance pre-configured for Docker, enabling you to deploy and manage containers like WordPress and MySQL Server quickly.

You’ll learn how to:

  • Generate and secure a custom SSH key pair to access the instance.
  • Use AWS CLI commands and configuration files to launch your Lightsail instance.
  • Apply a user-data script to automatically install Docker, Docker Compose, and supporting tools during creation.
  • Assign and attach a static IP address for reliable access.
  • Connect via SSH and verify your environment.
  • Clean up resources when they’re no longer needed.

By the end of this chapter, you’ll have a fully operational AWS Lightsail instance ready to run Docker containers for WordPress, MySQL and other applications in a secure and repeatable way.

Create a Custom SSH Key Pair

Before running ‘aws lightsail create-instances’, you need an SSH key pair so the AWS account can associate it with the new instance. The key pair provides the secure SSH credentials required to connect to the instance after it is created. If you skip this step, you won’t have a valid .pem file to authenticate with your server. By creating the key pair first, you ensure that when you launch the instance, it can be accessed securely using your private key immediately.

Create a directory (e.g., MyUbuntuInstance).

1. Create the SSH key pair

Run this in PowerShell (Windows) or bash (Linux/macOS):

aws lightsail create-key-pair --region ap-southeast-2 --key-pair-name MyUbuntuInstanceKeyPair --query privateKeyBase64 --output text > MyUbuntuInstanceKeyPair.pem --profile MyUbuntuProfile

Options explained:

  • aws lightsail create-key-pair This command tells the AWS Cli to create a new Lightsail SSH key pair.
  • --region ap-southeast-2 Specifies the AWS region (Sydney). If you don’t set this, the AWS Cli defaults to whatever is configured in your AWS profile.
  • --key-pair-name MyUbuntuInstanceKeyPair The name you’re giving to the new key pair in Lightsail. You’ll use this name later when creating an instance with –key-pair-name.
  • --query privateKeyBase64 Filters the command’s JSON output so that only the private key (in base64-encoded text) is returned, not the whole JSON response.
  • --output text Ensures the result is output as plain text instead of JSON. Without this, you’d get JSON formatting that isn’t usable as a .pem file.
  • > MyUbuntuInstanceKeyPair.pem Redirects the output (the private key) into a file called MyUbuntuInstanceKeyPair.pem. This file is what you’ll use with SSH.
  • --profile MyUbuntuProfile Selects which AWS CLI profile to use. This is helpful if you have multiple accounts or credentials configured.

2. Fix permissions

SSH requires that your .pem file is locked down. SSH refuses to use a .pem file if it’s too “open” (i.e., readable by other users). Locking it down ensures only you can read it.

Linux/macOS:

chmod 600 MyUbuntuInstanceKeyPair.pem

Options explained:

  • chmod – Change file mode (permissions).
  • 600 – Sets permissions so that:
    • Owner: Read and Write
    • Group: No permissions
    • Others: No permissions

Windows PowerShell:

icacls.exe MyUbuntuInstanceKeyPair.pem /inheritance:r

Options explained:

  • icacls.exe A Windows command-line tool used to view or modify file and folder access control lists (ACLs).
  • MyUbuntuInstanceKeyPair.pem Target file.
  • /inheritance:r Removes inherited permissions (so the file doesn’t inherit broad access rights from the folder).
icacls.exe MyUbuntuInstanceKeyPair.pem /grant:r "$($env:USERNAME):(R)"
  • /grant:r Grants permissions, replacing any existing ones.
  • "$($env:USERNAME)" Expands to your current Windows username.
  • :(R) Read-only permission.

3. List SSH Key pair names

aws lightsail get-key-pairs --region ap-southeast-2 --query "keyPairs[].name" --output text --profile MyUbuntuProfile

4. Deleting an SSH Key Pair

If you no longer need the key, delete both to keep your system and AWS environment tidy.

1. Delete the local .pem file

Linux/macOS:

rm MyUbuntuInstanceKeyPair.pem

Windows PowerShell:

icacls "MyUbuntuInstanceKeyPair.pem" /inheritance:e
  • /inheritance:e re-enables permission inheritance from the parent folder.
  • This means the file will now take on the normal ACLs (Access Control Lists) from its directory again, instead of being locked to just the user.
icacls "MyUbuntuInstanceKeyPair.pem" /reset
  • /reset wipes any custom permissions on the file.
  • After this, only the default inherited permissions apply (e.g. Administrators, your user, System). This step ensures you (and Windows) can manage or delete the file normally.
Remove-Item "MyUbuntuInstanceKeyPair.pem" -Force
  • Remove-Item deletes the file.
  • -Force bypasses prompts and ignores hidden/system attributes if set.
  • Now that inheritance is restored and ACLs are reset, Windows lets you remove the file without Access Denied errors.

2. Delete the SSH key pair from AWS Lightsail

First, check which key pairs exist in your region:

aws lightsail get-key-pairs --region ap-southeast-2 --query "keyPairs[].name" --output text --profile MyUbuntuProfile

Then delete the one you no longer need:

aws lightsail delete-key-pair --key-pair-name MyUbuntuInstanceKeyPair --region ap-southeast-2 --profile MyUbuntuProfile

Creating a Lightsail Instance

aws lightsail create-instances --cli-input-json file://lightsail-instance-config.json --user-data file://userdata.bash --profile MyUbuntuProfile

1. Create the Configuration File

Create a new file named lightsail-instance-config.json and add:

{
  "instanceNames": ["MyUbuntuInstance"],
  "availabilityZone": "ap-southeast-2a",
  "blueprintId": "ubuntu_24_04",
  "bundleId": "small_3_2",
  "userData":  "",
  "keyPairName": "MyUbuntuInstanceKeyPair",
  "tags": [
    {
      "key": "Docker",
      "value": "WordPress-Docker"
    }
  ]
}

2. Create external user-data file

Create a new file named userdata.bash and add:

#!/bin/bash

LOGFILE="/var/log/userdata.log"

log() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $*" >> "$LOGFILE"
}

log "Start user-data script"

log "sudo apt-get update -y"
sudo apt-get update -y

log "apt-get install -y libarchive-tools"
sudo apt-get install -y libarchive-tools

log "apt install -y zip"
sudo apt install -y zip

log "Install BashNovusTools"
sudo mkdir -p /etc/bashnovustools && curl -L https://github.com/novuslogic/BashNovusTools/releases/download/v0.1.3/BashNovusTools.v0.1.3.zip -o /tmp/bashnovustools.zip && sudo bsdtar -xf /tmp/bashnovustools.zip -C /etc/bashnovustools && sudo chmod +x /etc/bashnovustools/bin/*.sh && echo 'export PATH=\"/etc/bashnovustools/bin:$PATH\"' | sudo tee /etc/profile.d/bashnovustools.sh

# Update Ubuntu to latest packages
log "Update Ubuntu to latest packages"
sudo /etc/bashnovustools/bin/update-ubuntu.sh

# Install Docker Engine
log "Install Docker Engine"
sudo /etc/bashnovustools/bin/install-docker-engine.sh

# Install Docker Compose
log "Install Docker Compose"
sudo /etc/bashnovustools/bin/install-docker-compose.sh

# Add ubuntu user to docker group (will take effect on next login)
log "Add ubuntu user to docker group"
sudo /usr/sbin/usermod -aG docker ubuntu || true


log "End user-data script" 

Create a static IP

1. Pick a unique name for it (e.g. MyUbuntuInstanceStaticIP):

aws lightsail allocate-static-ip --static-ip-name MyUbuntuInstanceStaticIP --region ap-southeast-2 --profile MyUbuntuProfile

2. Attach a public static IP address to the instance

aws lightsail attach-static-ip --static-ip-name MyUbuntuInstanceStaticIP --instance-name MyUbuntuInstance --region ap-southeast-2 --profile MyUbuntuProfile

3. Verify

aws lightsail get-static-ip --static-ip-name MyUbuntuInstanceStaticIP --region ap-southeast-2 --profile MyUbuntuProfile

4. Test the SSH Connection

Replace <STATIC_IP> with the address returned above:

ssh -i MyUbuntuInstanceKeyPair.pem ubuntu@<STATIC_IP>

If you see a “bad permissions” warning on Linux/macOS, re-run chmod 600 MyUbuntuInstanceKeyPair.pem.
On Windows, re-apply the icacls steps.

Clean up resources

Are you finished with your AWS Lightsail instance? Before you move on, take a few minutes to clean up all associated resources. Not only will this help you avoid surprise charges, but it will also keep your AWS account organized and secure.

1. Release the Static IP

If you have a static IP attached to your instance, make sure to release it first. Otherwise, AWS may keep charging you for the reserved IP.

aws lightsail release-static-ip --static-ip-name MyUbuntuInstanceStaticIP --region ap-southeast-2 --profile MyUbuntuProfile

2. Delete the Instance

Next, delete the AWS Lightsail instance. This action is permanent and will result in the loss of all data on the instance.

aws lightsail delete-instance --instance-name MyUbuntuInstance --region ap-southeast-2 --profile MyUbuntuProfile

3. Delete the SSH Key Pair in AWS Lightsail

Next, Delete the SSH Key Pair

aws lightsail delete-key-pair --key-pair-name MyUbuntuInstanceKeyPair --region ap-southeast-2 --profile MyUbuntuProfile

Further Reading

Using WordPress on AWS Lightsail and Docker

Using WordPress on AWS Lightsail and Docker – Early Access Edition

Learn how to deploy WordPress on AWS Lightsail using Docker.

This book provides a clear, step-by-step guide to setting up the AWS CLI, creating a Lightsail virtual server, installing Docker, and deploying WordPress with Docker Compose.
You will also explore how to automate WordPress theme deployments using WP-CLI and CI/CD pipelines.

It is designed for developers, site owners, and technical users who want a simpler, more reliable, and more secure approach to WordPress deployment using DevOps practices.

Early Access Edition

Using WordPress on AWS Lightsail and Docker

Using WordPress on AWS EC2 Free Tier

Here is a guide on how to setup WordPress on Amazon EC2 Free Tier

Setup

  1. Sign up for a AWS Account at http://aws.amazon.com/

  2. Sign up for a Amazon EC2 at http://aws.amazon.com/ec2

  3. Sign into the AWS Console

  4. Choose a Region before launching your new EC2 instance.

     

  5. Create EC2 Linux Micro Instance for WordPress:
  6. To start a new EC2 instance click on the Launch Instance button.

  7. In the “Request Instances Wizard” tab to the Community AMI’s then filter using “wordpress” then choose the AMI:

    bitnami-wordpress-3.1-0-linux-ubuntu-10.04-ebs (ami-30f18f62)

  8. For your Free instance, choose the number of instances: 1, Availability Zone: No Preference and Instance Type: Micro (t1 micro, 613MB).

  9. Shutdown Behavior option should be stop, and all other options Use Default.

  10. Add in a tag key = Name and value = Webserver.

  11. Create a new Key Par call it the name of the website then create and save this file somewhere on your local machine that can be grabbed latter. E.g xyz.pem

  12. Adjust Security Groups,

    Add rules for SSH, HTTP, HTTPS but leave the source as 0.0.0.0/0

  13. Now Lunch the instance

  14. Assign Elastic IP then Associate Address with your EC2 Instance
  15. Click on Instances within the EC2 console to find the Public DNS.

  16. Install Open SSH on Windows
  17. Set pem file to Read by owner

     

    chmod 400 xyz.pem

  18. SSH in to the instance

    ssh -i xyz.pem bitnami@ec2-<public DNS>.ap-southeast-1.compute.amazonaws.com

  19. Move WordPress to run at the root of the apache web server by editing httpd.conf file using vi

     

    sudo vi /opt/bitnami/apache2/conf/httpd.conf

    DocumentRoot “/opt/bitnami/apache2/htdocs”

     

    To

     

    DocumentRoot “/opt/bitnami/apps/wordpress/htdocs”

    <Directory />

    Options Indexes MultiViews +FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all

    </Directory>

     

    <Directory “/opt/bitnami/apache2/htdocs”>

     

    To

     

    <Directory “/opt/bitnami/apps/wordpress/htdocs”>

     

    Comment out:

     

    #Include “/opt/bitnami/apps/wordpress/conf/wordpress.conf”

     

  20. Create an .htaccess file for WordPress

     

    This also enables you to have pretty permalinks like myblog.com/tour

     

    Add .htaccess file to WordPress dir

    in /opt/bitnami/apps/wordpress/htdocs/.htaccess

     

    # BEGIN WordPress

    <IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /

    RewriteCond %{REQUEST_URI} !=/server-status

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /index.php [L]

    </IfModule>

    # END WordPress

     

  21. Configure WordPress to know its own DNS entry

     

    sudo vi /opt/bitnami/apps/wordpress/htdocs/wp-config.php

     

    define(‘WP_HOME’, ‘http://www.ringio.com’);

    define(‘WP_SITEURL’, ‘http://www.ringio.com’);

     

  22. Install Filezila

     

    Public DNS

    SSH Username: bitnami

    Password: <Blank>

     

  23. delete the /opt/bitnami/updateip file. Otherwise, restarting the instance, Bitnami resets the wp_options values to the Public DNS server name.

     

    sudo rm /opt/bitnami/updateip

     

  24. Install EMS MySQL Manager

     

    How to Connect to BitNami MySQL Remotely

    http://wiki.bitnami.org/cloud/how_to_connect_to_your_amazon_instance#How_to_connect_to_the_BitNami_MySQL_remotely.3f

     

     

  25. Run this SQL script to set the Pubic IP Address with WordPress

     

    update wp_options set option_value = ‘http://www.agileweboperations.com’ where option_name in (‘siteurl’, ‘home’);

     

  26. Configure WordPress with the Pubic IP Address

     

    sudo vi /opt/bitnami/apps/wordpress/htdocs/wp-config.php

     

    define(‘WP_HOME’, ‘http://www.ringio.com’);

    define(‘WP_SITEURL’, ‘http://www.ringio.com’);

     

  27. Reboot the instance
  28. In your Browser type the public ip and see if WordPress is running correctly at Root Directory
  29. Login into Woresspress using default bitnami username

    Username: user

    Password: bitnami

  30. Add a new use into WordPress with Role of Administrator
  31. Then remove default bitnami username from WordPress by login in as your new username
  32. Make a DNS A record for the domain host provider, and use the elastic IP.

Migration

  1. Both wordpress on your old site and on AWS are the same due to database compatible issues
  2. Copy your \wp-content\upload from your old site locally to reload on AWS

    sudo chmod 755 /opt/bitnami/apps/wordpress/htdocs/wp-content/

    Install and download all plugins to your AWS Worspress instance

  3. Download or install your old theme and plugins
  4. Export your Old WordPress database using MyPHPAdmin
  5. Run the Export SQL Script on the AWS WordPress Instance using your Remote SQL Manager
  6. The rerun the SQL script to set the Pubic IP Address with WordPress

    update wp_options set option_value = ‘http://www.agileweboperations.com’ where option_name in (‘siteurl’, ‘home’);

To Finish

  1. When your domain has delegated run this script again with your domain

    update wp_options set option_value = ‘http://www.website.com’ where option_name in (‘siteurl’, ‘home’);

     

  2. Configure WordPress with the Pubic IP Address

     

    sudo vi /opt/bitnami/apps/wordpress/htdocs/wp-config.php

     

    define(‘WP_HOME’, ‘http://www.website.com’);

    define(‘WP_SITEURL’, ‘http://www.website.com’);

 

Links

Amazon Web Services
http://aws.amazon.com/

AWS Management Console
http://aws.amazon.com/console/

Bitnami Wordpres Stack
http://bitnami.org/stack/wordpress

OpenSSH
http://www.openssh.com/
http://sshwindows.webheat.co.uk/

Filezilla
http://filezilla-project.org/

How to Connect to BitNami MySQL Remotely
http://wiki.bitnami.org/cloud/how_to_connect_to_your_amazon_instance#How_to_connect_to_the_BitNami_MySQL_remotely.3f

EMS MySQL Manager
http://www.sqlmanager.net/products/mysql/manager