Seven Story Rabbit Hole

Sometimes awesome things happen in deep rabbit holes. Or not.

   images

Installing Ghost on AWS Lightsail With SQLite

Here are my requirements for a Ghost blogging platform backend:

  • Cheap – ideally under $5 / month
  • Ability to setup multiple blogs if I later want to add a new blog hosted on a different domain: so blog1.domainA.com + and blog2.domainB.com, without increasing cost.
  • Easy to manage and backup

Non-requirements:

  • High traffic
  • Avoiding CLI or some server management (would be nice, but does that exist for < $5 month?)

And here is the tech stack:

  • AWS Lightsail instance running Ubuntu 18
  • SQLite
  • Nginx
  • Node.js
  • Ghost Node.js module(s)

SQLite was chosen over MySQL since this is one less “moving part” and slightly easier to manage. See this blog post for the rationale.

Launch a Lightsail instance

Lightsail seems like a good value since you can get a decent sized instance and a static IP for $5.

Login to the AWS console and create a Lightsail instance with the following specs:

  • Blueprint: OS Only Ubuntu 18.04 LTS
  • SSH key: upload your ~/.ssh/id_rsa.pub (maybe make a copy and rename it with a better name to easily find it in the AWS console later)
  • Instance Plan: $5/mo with 1GB or RAM, 1 vCPU, 40 GB SSD and 2 TB of transfer. Ghost recommends at least 1 GB of RAM, so it’s probably better to use this instance size or greater.
  • Identify your instance: rabbit (or whatever you wanna call it!)

You should see the following:

LightSailInstance.png

Create a static ip

Go to the Lightsail Networking section, and choose “Attach static ip”. Associate the static ip with the lightsail instance, and make a note of it as you will need in the next step.

Add DNS A record

Go to your DNS register where you registered your blog domain name (eg, Namecheap), and add a new A record as follows:

DNSARecord.png

  • Use “blog” for the host if you want the blog named “blog.yourdomain.com”, but you could also name it something else.
  • Use the public static ip address created in the previous step.

Install Ghost dependencies

ssh in via ssh ubuntu@<your ligthsail instance ip>

Update the apt package list:

1
$ sudo apt-get update

Install nginx:

1
2
$ sudo apt-get install -y nginx
$ sudo ufw allow 'Nginx Full'

Install nodejs:

Add the NodeSource APT repository for Node 12, then install nodejs

1
2
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash
$ sudo apt-get install -y nodejs

Install Ghost-CLI

1
$ sudo npm install ghost-cli@latest -g

Create ghost blog

Create a directory to hold the blog:

1
2
3
4
$ sudo mkdir -p /var/www/ghost/blog1
$ sudo chown ubuntu:ubuntu /var/www/ghost/blog1
$ sudo chmod 775 /var/www/ghost/blog1/
$ cd /var/www/ghost/blog1/

Install Ghost:

1
$ ghost install --db sqlite3

Here is how I answered the setup questions, but you can customize to your needs:

  • Enter your blog URL: http://blog1.domainA.com
  • Do you wish to setup Nginx?: Yes
  • Do you wish to setup SSL?: No
  • Do you wish to setup Systemd?: Yes
  • Do you want to start Ghost?: Yes

I decided to setup SSL in a separate step rather than initially, but the more secure approach would be to use https instead, eg https://blog1.domainA.com for the blog URL, which will trigger SSL setup initially.

Create Ghost admin user

This part is a little scary, (and ghosts are scary), but Ghost basically puts your blog unprotected to the world without an admin user. The first person that stumbles across it gets to become the admin user. You want that to be you!

Quickly go to http://blog1.domainA.com and create the Ghost admin user.

Configure blog2 and map it’s DNS

Go to your DNS register where you registered your blog domain name (eg, Namecheap), and add a new A record as follows:

  • Use “blog” for the host if you want the blog named “blog.domainB.com”, but you could also name it something else.
  • Use the public static ip address from the Lightsail AWS console.
1
2
3
4
$ sudo mkdir -p /var/www/ghost/blog2
$ sudo chown ubuntu:ubuntu /var/www/ghost/blog2
$ sudo chmod 775 /var/www/ghost/blog2/
$ cd /var/www/ghost/blog2/

Install Ghost:

1
$ ghost install --db sqlite3

Use the same steps above, except for the blog URL use: http://blog.domainB.com

Congrats!

You now have two separate Ghost blogging sites setup on a single $5 / mo AWS Lightsail instance.

References

Comments