Installing Ghost on AWS

Installing Ghost on AWS
Photo by Lan Gao / Unsplash

This post shows in detail how to install the Ghost platform in the Amazon cloud and self host a blog. You will need to have an AWS account with Administrator privileges in order to follow along but this can be done with a one year free trial.

Login to AWS and access the EC2 service in order to create a virtual server. Choose the region in which you wish the server to be located. I chose London.

Select the Launch instance option. Give the new instance a name, say Ghost Server, and then scroll down and select the Ubuntu image.

You can see that the Ubuntu server is Free tier eligible which allows you to test AWS and your self hosted Ghost setup for up to a year.

Scroll down further and select the Create new key pair link. Within the popup window, enter a name for your key pair such as Ghost-Key-Pair and then select the Create key pair button. Be sure to download the private key file to your computer. This file will be required to access your server so keep it safe.

Scroll down further and select your security group settings. Keep the Create security group default. Keep the Allow SSH traffic from default but optionally change the Anywhere setting to My IP for additional security. Select Allow HTTPS traffic from the internet and Allow HTTP traffic from the internet to enable Ghost to serve http(s) traffic. Bear in mind that even if you don't require http access for reading your blogs, it is still required for automatic update of your SSL certificate.

Scroll down to the Configure Storage section. Free tier eligible customers can get up to 30 GB of EBS General Purpose (SSD) or Magnetic storage. Change the storage from the default 8 to 30 GiB. Other configurations would be possible such as an 8 GiB root volume and an additional 22 GiB encrypted volume.

The Ghost.org website details here the software to install prior to installing Ghost itself. This includes NGINX, MySQL and Node.js.

Scroll down and open the Advanced details section. Within the section, find the User data (optional) text area. This field can be populated with commands that need to be executed only once by the new server instance. For example, new applications can be loaded. The commands will run with root access so no sudo command is required. I have created a file below that you can download to your client computer and then upload into the User data field within AWS. The file uses a site name ghost-blog which can be changed prior to uploading it.

Once you have uploaded the commands into the User data (optional) text area, select the Launch instance button and your virtual linux server will be created and launched.

Now that we have a running instance, we can associate an elastic IP address with the running instance. This is a public IP address. You can now connect to the instance using ssh.

ssh ubuntu@[ip address] -i c:\Users\Robin\.ssh\Ghost-Key-Pair.pem

Check the log in /var/log/cloud-init-output.log to ensure the commands executed properly.

Give the root MySQL user a password your-new-root-password. Store it safely. You will need the password you created during the Ghost installation itself.

# Enter mysql
sudo mysql
# Update permissions
ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY '<your-new-root-password>';
# Reread permissions
FLUSH PRIVILEGES;
# exit mysql
exit

You need to own a domain name to point to your public IP address. Once you have a correctly configured domain name, you will be in a position to fully install Ghost.

Run the install process

Now we install Ghost with one final command.

cd /var/www/ghost-blog
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. Since MySQL is installed on the same server, use localhost (press Enter to use the default value).

MySQL username / password

Enter root as the username and then supply the password that you entered earlier.

Ghost database name

Enter the name of your database. It will be automatically set up for you.

Since 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. You will need http access to your server for the SSL setup to work.

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.