Installing Ghost on a VPS with Ubuntu 20.04
11 min read

Installing Ghost on a VPS with Ubuntu 20.04

Installing Ghost on a Vultr compute or high frequency compute instance with a minimum of 1GB memory.

If you liked this tutorial and want to support me you can do so by visiting my: Ko-fi page and buy me a coffee.

If you have a VPS (with Ubuntu 20.04 installed on it and a minimum of 1GB of memory) with a other provider than Vultr.com you can still follow this guide. Be sure to note down your server IP address, root login name and password, because we will need those.

After you have noted those down you can skip to these parts of the guide: DNS settings, For cloudflare users read this first, Setting up your server and Extra Step for Cloudflare users

For all other users who want to follow the full tutorial read further below.

$100 to test out Vultr.com

If you don't have a vultr.com account, you can create one by using our affiliate link. When using our affiliate link you will get $100 to try out their platform

Intro

In this Tutorial we're going to install Ghost on the $6.00 high frequency compute instance from Vultr.com. You can also choose the cloud compute instance that will cost $5.00 both have 1GB of memory.

The main difference between the two instances is that the high frequency compute instance has 32 NVMe storage vs the 25GB SSD storage on the cloud compute instance.

Deploying your Vultr.com instance

In this step will be deploying the Vultr.com high frequency compute instance.

If you don't have an account yet with Vultr.com, you can create one by using our affiliate link and as explained earlier receive $100 to try out their service.

If you do have an account with Vultr.com, login and click on the blue button with the plus sign on it.

Blue-button

After you clicked on the blue button, you will be directed to the Deploy New Instance page.

On the Deploy New Instance page we will first choose the server we want, either the High Frequency or the Cloud Compute one.

In our expample we choose the High Frequency one.

Choose-server

Now choose your server location. (any location will work, but choose the one closest to you, for best performance)

Server-location

Next step is the server type, here we choose Ubuntu 20.04 x64 (the latest LTS release). To select the correct version click on Ubuntu and select Ubuntu 20.04 from the drop down menu.

Server-type

Choosing our server size is the next step, any server with atleast 1GB of memory will work. In our example we go for the 32 GB NVMe that will cost $6/month

Server-size

Now you can choose some additional features, the only one we selected is the Enable IPv6, although in this tutorial/guide we wont be using it, so you could leave it blank if you want.

Additional-features

You could also choose to Enable Auto Backups at this stage, that will cost you a $1.20/month extra on top of the $6/month, but we choose not to, because you can always enable it later from within your Vultr.com account if you realy want to have backups of your whole instance.

We will skip the startup script and ssh keys part and go on with the Server Hostname & Label. Here you can just enter your domainname, in our case we used: bobvanzeeland.com

Server-hostname

After you entered a Server Hostname & Label click on the big blue Deploy Now button.

Deploy-now

Your server will now be deployed, this can take a few minutes to complete.

When your server is fully deployed and running you can see it in your Vultr.com account. Now click on your instance (the name you gave your server in the Hostname & Label part) and take a note of your IP Address, Username and Password we will use those to connect with the server and install all needed software for your Ghost blog.

DNS settings

Before we start be sure to change the DNS records for your domain name at your domain registrar and point the A record to your IP address you just got from deploying your server.

We use Cloudflare to manage our DNS, you can sign up with Cloudflare for free and add your domain name there. When adding your domain name on Cloudflare you will be asked to change your nameservers to theirs (they have multiple guides for different domain registrars on how to change the nameservers.

DNS and nameserver changes can take up to 24 hours to process, but in most cases they will be processed in a few minutes or hours depending on your domain extention type.

Once your domain name is active on Cloudflare, DNS record changes are almost instantaneously.

Connecting to your server with SSH

We are using a Windows 10 machine to make and run this tutorial/guide so to connect to our server will be using PuTTY a free SSH client to connect with your server. You can use any other SSH client if you want, this tutorial/guide will work in all of them.

If you choose to use PuTTY start it up, and enter your server IP address in the Host Name (or IP address) text field and after that click on Open. If you're using a other SSH client see that clients readme on how to connect to a IP address.

After you pressed on Open in PuTTY you will open up a terminal. Here you will be asked for your login (the username you noted earlier). On Vultr.com all instances have root as the default username so enter: root followed by pressing in enter.

Now you'll be asked to input your password (use the password you made a note off) do this and press enter afterwards.

Note: To paste text you copied from outside PuTTY e.g. your password and later on commands to install and configure your server inside PuTTY, you click on your right mouse button when the focus is on your PuTTY terminal and to copy something inside PuTTY you select the text you want to copy with your left mouse button, all selected text will be copied to you windows clipboard. For more information about copy and paste see: PuTTY FAQ

When we are logged in on our server you will see something like:
[email protected]<yourdomain>:~# here we will enter all our commands

For cloudflare users read this first

If you use cloudflare dns for your website, pause it temporary inside your cloudflare account, so we wont get any conflicts when setting up SSL later on in this tutorial/guide

(when you select your domain on cloudflare you can find a advanced action block on the bottom right)

pause-cloudflare

Setting up your server

We will now go through a couple of steps to add a new user to the server, update the server and install als required software needed for ghost onto the server.

Step 1: Adding a new user to the server

First thing will do is add a new user to the server with the following command: (replace <user> with your preffered username e.g. bob adduser bob)

adduser <user>

when executing the above command you will be asked for a new password, choose a secure password an take a note of it. You will also be asked to input some other personal information, you can just leave that blank and press enter on all of them. After you added the new user will continue to step 2.

Step 2: Add the user to the superuser group and give the user admin privileges

To add the user to the superuser group and give the user admin privileges we enter the following command: (replace <user> with the username you created in step 1)

usermod -aG sudo <user>

Step 3: Login as the new user

Now we're going to login as the new user by using the following command:

(Again replace <user> with the username you created in step 1, when you are being asked for a password, enter the password you gave to the new user we created in step 1.)

su - <user>

Step 4: updating the server

We will now update all the packages on the server to use the latest versions available.

The first command we need to use for this is:

(again when you are being asked for a password, enter the password you gave to the new user we created in step 1.)

sudo apt-get update

This command will update the package list with the latest available versions.

It will however not update or upgrade the packages, for that we will run the following command:

sudo apt-get upgrade

This command will update all the installed packages on your server, when asked press Y or Yes followed by enter to install everything.

Step 5: Installing our webserver NGINX

For our webserver will be using NGINX. To install NGINX enter the following command:

sudo apt-get install nginx

We will now also add NGINX to the firewall to allow http and https traffic by entering the following command:

sudo ufw allow 'Nginx Full'

(again when you are being asked for a password, enter the password you gave to the new user we created in step 1.)

Step 6: MySQL installation

Next were installing MySQL as our database with the following command:

sudo apt-get install mysql-server

(again when you are being asked for a password, enter the password you gave to the new user we created in step 1.)

Step 7: login on MySQL and change the default password

To log into MySQL type the following command:

sudo mysql

after you are logged in to MySQL, change the default password by using the following command: (replace <password> with a new secure password and make a note of it.)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<password>';

After you changed the password type the following command to exit mysql:

quit

Now login as your user again with the following command:

su - <user>

(again replace <user> with the username you created in step 1 and if asked for a password use the one you created for this user in step 1.)

Step 8: Installing Node.js

We also need to install Node.js, there are multiple versions of Node.js but for ghost the current recommended version is 14.x (Node v14 Fermium LTS). To install version 14 of Node.js we first retrieve the files with the following command:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash

and when that step is completed we install Node.js with the following command:

sudo apt-get install -y nodejs

Now that Node.js is installed we can finnaly begin with the installation of Ghost in step 9.

Step 9: Ghost installation

To install Ghost we first need to install the Ghost Command Line Interface (Ghost CLI) with the Ghost Command Line Interface we can install, update and configure our Ghost installation.

To instal the Ghost CLI enter the following command:

sudo npm install [email protected] -g

Step 9.1: Creating the directories

Before we install ghost we need to create and prepare our directories where all the files will be stored.

To create our first directory we use the following command:

(replace <your directory name> with the name you like to give your directory, e.g. sitename will look like this /var/www/sitename )

sudo mkdir -p /var/www/<your directory name>

Now will set the owner of the directory with the following command:

(Replace both <user> in <user>:<user> with the user you created in step 1 e.g. bob:bob and replace <your directory name> with the name you used in the previous command so for example we get sudo chown bob:bob /var/www/sitename)

sudo chown <user>:<user> /var/www/<your directory name>

Next we give the directory the correct permissions with the following command:

(Again replace <your directory name> with the one you used for your directory e.g. with sitename you get sudo chmod 775 /var/www/sitename)

sudo chmod 775 /var/www/<your directory name>

Where almost there now, next up will navigate to our root directory where we finnaly install Ghost. To go to your root directory enter the following command:

(Again replace <your directory name> with the one you used for your directory e.g. with sitename you get cd /var/www/sitename)

cd /var/www/<your directory name>

Step 9.2 Installing Ghost

From inside the root directory of your website enter the following command:

ghost install

This command will first download all the files you need and afterwards, you will be asked a couple of questions to complete the installation of Ghost.

We will go through all these question step by step now.

Blog Url

Here you will enter your full URL e.g. https://example.com be sure to use https:// and not http:// if you want to use SSL

MySQL hostname

This step we will keep the default settings so just press enter.

MySQL username/password

For MySQL username we enter root after that you will be asked for a password, use the one you created in Step 7

Ghost database name

We will be asked for a database name here, just keep the default one, so press enter to continue.

Set up a ghost MySQL user?

Now we are being asked if we want to setup up a ghost MySQL user, type Yes or Y to setup the Ghost user and continue to the next step.

Setup NGINX

In this step we are being asked if we want NGINX to be set up for us, we will say Yes and press enter

Set up SSL

A reminder first for cloudflare users, pause your website on cloudflare before you continue with this step

You will be asked if you want to setup SSL with Let's Encrypt (it's free), we choose yes here. When you choose Yes for this step, you will be asked to enter your email address, this will be used to notify you for things related to your SSL certificate from Let's Encrypt.

Set up systemd

Here will be asked if we want systemd to be set up. Choose yes systemd will make sure that the ghost process will run smoothly and gets restarted in case of a server reboot.

Start Ghost?

The last step askes if you want to start Ghost. Choose yes to start Ghost

Step 10 Creating your Ghost admin account

The last step is to navigate to your website e.g. https://expamle.com/ghost

Here you will find a sign-up form to create your admin account for your website.

After you created your admin account you can start creating content on your freshly installed Ghost Blog!

Extra Step for Cloudflare users

If you paused your website on cloudflare in the previous steps, go back to your cloudflare account now but before you unpause your website, go to SSL/TLS and put it on Full (strict)

cloudflare-ssl

This step will prevent you from getting ERR_TOO_MANY_REDIRECTS in Firefox or a equivalent error in a other browsers.

After you have done the above step you can enable cloudflare again on your website.

enable-cloudflare

If you liked this tutorial and want to support me you can do so by visiting my: Ko-fi page and buy me a coffee ;)