8 min read

Guide: How to set up a Ghost Blog on AWS

Guide: How to set up a Ghost Blog on AWS
Ghost

Ghost is an open-source blog platform built on Node.JS, allowing media creators to publish, share, and grow a business around their content. It comes with modern tools to build a website, publish content, send newsletters & offer paid subscriptions to members. It's an alternative to WordPress or Drupal. Ghost started as a Kickstarter project and has over 3M+ installs. You can learn more about their story here.  

💡
Node.js is an open-source, server-side JavaScript runtime environment that allows developers to build scalable and high-performance network applications. It is based on the V8 JavaScript engine, which is developed by Google and is used in the Google Chrome web browser.

The fastest and easiest way to start with Ghost is to set up a site on Ghost(Pro).

A second option is to set up and run a self-hosted instance via Digital Ocean or Amazon Web Services.   Another option is to set up Ghost via a Bitnami image on Amazon Lightsail.

This guide walks you through setting up Ghost on an EC2 instance on AWS.  

💡
You can use ChatGPT to follow these steps and ask for clarification as you run into any issues. Link to a prefilled prompt: https://chat.openai.com/share/3ba9df0d-31b1-4d58-b22a-9848f46eed23

Step 1: Set up an Amazon Web Services account


First, sign up for an Amazon Web Services (AWS) account if you don't already have one by visiting aws.amazon.com.


Step 2: Create an EC2 Instance


Create an Amazon Elastic Compute Cloud (EC2) instance. This will be the virtual machine that hosts your Ghost blog.

EC2 stands for Elastic Compute Cloud. Ghost recommends a  Ubuntu server with at least 1GB of memory to run Ghost. The official guide for self-hosting Ghost recommends a stack of Ubuntu 16.04, 18.04, 20.04, or 22.04.

A. Navigate to EC2 in your account and "Launch an Instance."

B. Give your Instance your preferred name

C. Select Ubuntu 22.04 as the Amazon Image Type

D. For the "Instance Type," select "t3.Micro."

T3.Micro will support the installation of the Ghost blog until you need more resources based on traffic. T3. Micro's are also free tier eligible.

E. Make sure you set up a Key Pair for logging into the Instance, as a key pair provides a secure connection.

F. Network Settings

  • Select "Create a security group"
  • Select the check boxes next to "Allow SSH Traffic", "Allow HTTPS traffic from the internet" and "Allow HTTP traffic from the internet" to allow web server traffic.

F. Configure the Instance storage to 25 GB. This volume will work during the initial launch of the blog and can be expanded as needed.


Step 3: Allocate an Elastic IP

  1. Navigate to the Amazon EC2 console: https://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose Network & Security, Elastic IPs.
  3. Choose Allocate Elastic IP address.
  4. For Public IPv4 address pool, choose one of the following:
  • Amazon's pool of IPv4 addresses—If you want an IPv4 address to be allocated from Amazon's pool of IPv4 addresses.
  • Public IPv4 address that you bring to your AWS account—If you want to allocate an IPv4 address from an IP address pool that you have brought to your AWS account. This option is disabled if you do not have any IP address pools.
  • Customer-owned pool of IPv4 addresses—If you want to allocate an IPv4 address from a pool created from your on-premises network for use with an AWS Outpost. This option is disabled if you do not have an AWS Outpost.

Most users can default to selecting from Amazon's pool of IPV4 addresses.

(Optional) Add or remove a tag.  A tag is a label that you assign to an AWS resource. Each tag consists of a key and an optional value. You can use tags to search and filter your resources or track your AWS costs.

Choose Add new tag and do the following:

  • For Key, enter the key name.
  • For Value, enter the key value.[Remove a tag] Choose Remove to the right of the tag’s Key and Value.

5. Choose Allocate.

Once your Elastic IP is set up, click on it to associate the IP with the Instance set up in Step 2.

  1. In the navigation pane, choose Instances.
  2. Select the instance.
  3. Choose Actions, and then choose Associate Elastic IP.
  4. In the Associate Elastic IP dialog box, choose Use an existing Elastic IP address, and then choose the Elastic IP address that you want to use from the list.
  5. Choose Associate.



Step 4: Set up a Domain

You will need a domain name to host your blog. There are multiple Domain registrars, and you can buy any domain registrar of your preference. After registering your domain, you will need to configure the DNS records at the domain registrar with the public IP address assigned to the EC2 Instance.

Before setting up Ghost, you should set up a working DNS A-Record from your domain, pointing to the server's IP address. This step must be taken in advance so SSL can be configured during setup.

Here at Analogous Structures Labs, we use Namecheap and follow the steps here.

Step 5: Connect to the EC2 Instance

Login to our new EC2 Instance and follow the Ghost installation steps. There are two options:

  • Via the EC2 console
  • Via SSH

Via the EC2 console:

  • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
  • Choose Instances in the navigation panel
  • Select the newly created Instance and choose Connect.
  • Verify the user name and choose Connect to open a terminal window.

Via SSH:

If you wish to connect in other ways, such as SSH, check the official guide here.

  • Navigate to your Instance, click "Connect," and navigate to "SSH Client."
  • Follow the steps listed.

Step 6: Setup Ghost


Create a Ubuntu User

Create a new user with super-user privileges for running the Ghost server, and change to the newly created user.

$ sudo adduser ghost_blog 
$ sudo usermod -aG sudo ghost_blog 
$ su - ghost_blog
Note: Using the user name ghost causes conflicts with the Ghost-CLI, so it’s important to use an alternative name.


Update packages

Ensure package lists and installed packages are up to date.

# Update package lists
sudo apt-get update

# Update installed packages
sudo apt-get upgrade

Follow any prompts to enter the password you just created in the previous step.


Install NGINX

Ghost uses an NGINX server and the SSL configuration requires NGINX 1.9.5 or higher.

# Install NGINX
sudo apt-get install nginx

If ufw was activated, the firewall allows HTTP and HTTPS connections. Open Firewall:

sudo ufw allow 'Nginx Full'

Install MySQL

Next, you’ll need to install MySQL to be used as the production database.

# Install MySQL
sudo apt-get install mysql-server



Install Node.js

You will need to have a supported version of Node installed system-wide in the manner described below. If you have a different setup, you may encounter problems.

# Add the NodeSource APT repository for Node 16
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash

# Install Node.js
sudo apt-get install -y nodejs

Once the installation is complete, check the Node.js version to verify.

$ node -v
v16.10.1
Note: Your version may differ from version above

Install Ghost-CLI

Ghost-CLI is a command line tool to help you get Ghost installed and configured for use, quickly and easily. The npm module can be installed with npm or yarn.

sudo npm install ghost-cli@latest -g

Once installed, you can always run ghost help to see a list of available commands.


Install Ghost

Once your server is correctly setup and ghost-cli is installed, you can install Ghost itself. The following steps are the recommended setup. If you need more fine-grained control, the CLI has flags and options that allow you to break down and customize the install steps.

Create a directory

Ghost must be installed in its own directory, with a proper owner and permissions.

# Create directory: Change `sitename` to whatever you like
sudo mkdir -p /var/www/sitename

# Set directory owner: Replace <user> with the name of your user
sudo chown <user>:<user> /var/www/sitename

# Set the correct permissions
sudo chmod 775 /var/www/sitename

# Then navigate into it
cd /var/www/sitename

Run the install process

Now we install Ghost with one final command.

ghost install

Install questions

During install, the CLI will ask a number of questions to configure your site.

Blog URL

Enter the exact URL your publication will be available at and include the protocol for HTTP or HTTPS. For example, https://example.com. If you use HTTPS, Ghost-CLI will offer to set up SSL for you. Using IP addresses will cause errors.

MySQL hostname

This determines where your MySQL database can be accessed from. When MySQL is installed on the same server, use localhost (press Enter to use the default value). If MySQL is installed on another server, enter the name manually.

MySQL username / password

If you already have an existing MySQL database, enter the the username. Otherwise, enter root. Then supply the password for your user.

Ghost database name

Enter the name of your database. It will be automatically set up for you, unless you’re using a non-root MySQL user/pass. In that case the database must already exist and have the correct permissions.

If you provided your root MySQL user, Ghost-CLI can create a custom MySQL user that can only access/edit your new Ghost database and nothing else.

Sets NGINX up automatically enabling your site to be viewed by the outside world. Setting up NGINX manually is possible, but why would you choose a hard life?

If you used an https Blog URL and have already pointed your domain to the right place, Ghost-CLI can automatically set up SSL for you using Let’s Encrypt. Alternatively you do this later by running ghost setup ssl at any time.

SSL certification setup requires an email address so that you can be kept informed if there is any issue with your certificate, including during renewal.

systemd is the recommended process manager tool to keep Ghost running smoothly. We recommend choosing yes but it’s possible to set up your own process management.

Start Ghost?

Choosing yes runs Ghost, and makes your site work.



Check Ghost running status

We can check whether Ghost is up and running with the Ghost CLI command ls.

$ ghost ls
+ sudo systemctl is-active ghost_blog-mycoolblog-com

You’ll see an output like this.

NameLocationVersionStatusURLPortProcess Manager
blog-mycoolblog-com/var/www/cool_blog3.41.3running(production)https://mycoolblog.com2368systemd

If it’s still in stopped status and not running, start Ghost with the CLI command start.

$ ghost start



Accessing the New Blog

If you have already configured the DNS records, you can now access your Ghost blog with the URL you set up during installation.

Propagation and update of DNS records could take up a few hours, so if you have just configured your DNS settings, it may not be possible to access the URL. In that case, you could test the Ghost blog by using the IP address instead of the URL like https://x.x.x.x, where x.x.x.x is the public IP address of the EC2 instance.

If things go well, you will be presented with the home page of the new Ghost blog, with some sample posts.