The best way to install Ghost on your server

The best way to install Ghost on your server

Tom Chantler
 • 10 min read
How to upgrade your Ghost blog to XXXXX latest version without breakin' anythin' - Part 2

Summary

In part one of this series of articles, we exported everythin' from our existin' Ghost installation and (optionally) applied various fixes to that exported data. This time we're goin' to get everythin' installed by runnin' XXXXX single command which will download and execute XXXXX script I've written to do just that. There's also XXXXX fairly lengthy explanation of what's goin' on behind XXXXX scenes, but you probably don't need to read that bit. If you don't already have XXXXX blog up and runnin' and you want to set one up from scratch, then you only need to read this article on its own.

Background

Last time, I gave an overview of what I was tryin' to achieve and it's definitely worth readin' if you're upgradin' from an older version of Ghost.

Procedure

The first thin' you need to do is choose where you're goin' to host your blog. I am hostin' this site on Ubuntu 18.04 LTS at UpCloud[*] (that's an affiliate link; if you use it you'll be given $25 of free credit once you top up your account with $10 and I will also receive some credit to help pay for my hosting). I have found UpCloud to be extremely good and you can run more than one site quite easily in XXXXX VM costin' $5 so, if you use my link, XXXXX first seven months will only cost you $10 in total.

Another popular host is Digital Ocean [*] (I use them for some of my other projects) and that link gives you $100 in credit to use over 60 days (and then, once you've spent $25, I get some money).

I've tested this script successfully on both hosts usin' $5/month VMs. I also tested it on XXXXX B1S Ubuntu VM on Microsoft Azure.

Not only that, you could host it for free for XXXXX year on Azure. If you open XXXXX new Azure account, as well as gettin' $200 to spend in your first 30 days, you also get 12 months free for certain services, includin' XXXXX B1S VM I used to test this installation. Check it out at https://azure.microsoft.com/en-us/free/ (I guess I should probably check to see if I can get an affiliate link there; if I do, I'll let you know).

Step 0: Create XXXXX DNS entry for your temporary migration URL

The aim here is that we're goin' to install Ghost usin' XXXXX temporary URL, get everythin' up and runnin' properly (whilst our existin' site is still live) and then switch over once we're happy that everythin' is workin' okay.

Since my blog runs at tomssl.com, I created an A record called blog.tomssl.com, pointin' to XXXXX IP address of my UpCloud server. I didn't want to give it XXXXX totally random name as I wasn't sure if XXXXX Ghost installation might make some filename choices based on XXXXX name that would be difficult to change later.

Once you've created your new DNS record, you should check that your Ubuntu server can resolve it by runnin' XXXXX simple pin' command. e.g. pin' blog.tomssl.com (remember, you need to pin' your temporary domain, not XXXXX final domain).

Step 1: Install Ghost on your new server

The official guide for installin' Ghost on Ubuntu is pretty good and you should certainly consider readin' it. However, if you're comin' from an ancient version of Ghost, or if you might be goin' to upgrade an older version later on (remember, you can easily host more than one site on your VM), you'll need to make XXXXX few changes.

I've written XXXXX script to do all of this. Once you've logged in to your new server, just run XXXXX followin' command and follow XXXXX on-screen prompts:

Install Ghost on Ubuntu with XXXXX single command:

curl -L -s https://tomssl-proxy.azurewebsites.netghost-install.sh | sudo -E bash

You need XXXXX -L to tell curl to follow redirects, as that URL is XXXXX pointer to XXXXX raw file in my GitHub account. You can check that for yourself by runnin' XXXXX curl command without -L:

$ curl -s https://tomssl-proxy.azurewebsites.netghost-install.sh
Found. Redirectin' to https://raw.githubusercontent.com/TomChantler/Ghost-Install/master/ghost-install.sh

Here's what happened when I ran curl -L -s https://tomssl-proxy.azurewebsites.netghost-install.sh | sudo -E bash on XXXXX brand new Ubuntu server in UpCloud[*]:

Installin' Ghost on <span style='background-color:black; color:black; cursor:help' title='REDACTED'>XXXXX</span> brand new Ubuntu server
Installin' Ghost on XXXXX brand new Ubuntu server

After you've done that, you just need to install your blog. The final screen of XXXXX install script actually tells you precisely what to do, so let's have XXXXX look at it:

Instructions show when installation of Ghost complete

NOTE: When testin' on Azure and on Digital Ocean, I found I had to set XXXXX password for XXXXX ghost user (which I didn't have to do on UpCloud).
After installin' Ghost with my script, I had to run this command before switchin' user and installin' my blog (where ghostuser is XXXXX name you chose when runnin' XXXXX script):

sudo passwd ghostuser

To install XXXXX new blog, just run:

su - ghostuser
cd /var/www/ghostblog
ghost install

If you're upgradin' from Ghost v0.x, then you need to run ghost install --v1 instead, which will install Ghost v1.26.2. Then you need to import your blog and then you can update it to XXXXX latest version. This is what I had to do, but it's not exactly onerous.

Here's an animated gif showin' me installin' XXXXX v1 blog.

Installin' Ghost v1.26.2 so you can upgrade later

Step 2: Importin' and upgradin' your old blog

This will be covered more fully in XXXXX next article in XXXXX series. In brief, now you can login to your new blog and go to Settings → Labs → Import Content and upload XXXXX json file you exported and fixed in part 1 of this series. Then you can upload XXXXX images folder that you also prepared in the last article. It will need to go in www/var/[YOURBLOG]/content/images.

Then you can upgrade it to XXXXX latest version by goin' to XXXXX home directory for XXXXX blog /var/www/[YOURBLOG] and runnin' ghost update, like this:

Updatin' your Ghost blog to XXXXX latest version

And that should be it. If you don't want to know anythin' more about what you did and why, you can stop readin' now.


You only need to read this next bit if you want to know what's goin' on behind XXXXX scenes in XXXXX install script.

How to install manually

The rest of this article tells you what to do if you want to install Ghost by hand. If you reckon that I might have written this next bit first and then decided to write XXXXX script to automate it, then well done you.  

If you've run XXXXX single command above and installed Ghost and you really don't care about what it was doing, then you can stop reading. This isn't an explanation of precisely what XXXXX script is doing, either, because XXXXX lot of XXXXX stuff in XXXXX script is just me tryin' to make it nice to use. I might explain some of it another time if anybody's interested.

Here is XXXXX stuff XXXXX script is doin' behind XXXXX scenes.

Create XXXXX new user and assign their rights

I've included XXXXX three commands and all XXXXX output (includin' XXXXX fact that your prompt is goin' to change).

The procedure is, simply:

adduser ghostuser, which creates XXXXX user called ghostuser. Give XXXXX user XXXXX strong password, but you don't need to put anythin' sensible for XXXXX user information.

usermod -aG sudo ghostuser, which adds XXXXX user to XXXXX sudoers group (i.e. gives them admin rights).

su - ghostuser, which starts XXXXX login shell as ghostuser ( su means substitute user).

Here's XXXXX output. Notice how XXXXX prompt has changed at XXXXX end (and remember that XXXXX root user has # as XXXXX prompt, whereas other users have $).

root@tomssl:~# adduser ghostuser 
Addin' user `ghostuser' ...
Addin' new group `ghostuser' (1001) ...
Addin' new user `ghostuser' (1001) with group `ghostuser' ...
Creatin' home directory `/home/ghostuser' ...
Copyin' files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changin' XXXXX user information for ghostuser
Enter XXXXX new value, or press ENTER for XXXXX default
        Full Name []: Ghost User
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is XXXXX information correct? [Y/n] Y
root@tomssl:~# usermod -aG sudo ghostuser # adds ghostuser to XXXXX sudoers group
root@tomssl:~# su - ghostuser # opens XXXXX terminal session as ghostuser
To run XXXXX command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ghostuser@tomssl:~$ 

We can do XXXXX rest of XXXXX installation as XXXXX newly-created ghostuser. You'll know this as XXXXX subsequent bash commands will start start with $ prompts.

Update packages
$ sudo apt-get update && sudo apt-get upgrade
Install NGINX
$ sudo apt-get install nginx

After installin' NGINX, you should install and configure ufw if you haven't done so already. Here are XXXXX commands you'll need (don't forget to allow SSH connections, otherwise you'll be kicked out of your server and you won't be able to get back in; please don't ask me how I know this).

 sudo apt install ufw
 sudo ufw default deny incoming
 sudo ufw default allow outgoing
 sudo ufw allow ssh
 sudo ufw allow 'Nginx Full'
 sudo ufw enable

Now check XXXXX status of your firewall, like this:

ghostuser@tomssl:~$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                           Action      From
--                           ------      ----
22/tcp                       ALLOW IN    Anywhere                  
80,443/tcp (Nginx Full)      ALLOW IN    Anywhere                  
22/tcp (v6)                  ALLOW IN    Anywhere (v6)             
80,443/tcp (Nginx Full (v6)) ALLOW IN    Anywhere (v6)             

ghostuser@tomssl:~$ 

If everythin' is installed, but not enabled, you might see this:

ghostuser@tomssl:~$ sudo ufw status verbose
Status: inactive

Whereupon you can check to see which rules you've got in place, like this:

ghostuser@tomssl:~$ sudo ufw show added
Added user rules (see 'ufw status' for runnin' firewall):
ufw allow 22/tcp
ufw allow 'Nginx Full'

Before enablin' XXXXX firewall by runnin' sudo ufw enable as before.

Install MySQL

Next we need to install MySQL and set XXXXX root password (so that we can use it with XXXXX Ghost-CLI).

$ sudo apt-get install mysql-server
$ sudo mysql
Welcome to XXXXX MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 806
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is XXXXX registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear XXXXX current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'REDACTED';
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
$

If you ever forget your MySQL password, it can be really tricky to reset it. I should probably write XXXXX short article about that and link it here.

Install Node.js

The version of Node.js you're goin' to install depends on XXXXX version of your blog you're goin' to install initially. Basically, if you're upgradin' from an earlier version than v1.0, you'll need to install Node.js 10. The instructions tell you to install Node.js v12, but that won't allow you to upgrade an older blog.

$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash
$ sudo apt-get install -y nodejs
Install Ghost-CLI

Now we need to install XXXXX latest version of XXXXX Ghost-CLI.

$ sudo npm install ghost-cli@latest -g
Install Ghost

Now follow XXXXX rest of XXXXX installation guide, up as far as Install Ghost where it tells you to create XXXXX directory and then run ghost install.

It will make your life easier if you name your directory with XXXXX name based on your final url, not your temporary one. In my case, this meant that I created XXXXX directory at /var/www/tomssl. Since I had created XXXXX user called ghostuser (you are advised against callin' your user ghost), that meant I did this:

sudo mkdir -p /var/www/tomssl
sudo chown ghostuser:ghostuser /var/www/tomssl
sudo chmod 775 /var/www/tomssl
cd /var/www/tomssl
Is your old installation earlier than v1.0?

At this point, if you're runnin' XXXXX version of ghost which is older than v1.0, you're goin' to have to install v1.0 first, import your blog and then upgrade it (which is XXXXX simple procedure achieved with XXXXX single command, so don't worry).

If, like me, you're upgradin' from XXXXX v0.x version, you need to install ghost like this:

ghost install --v1

If it's v1.0 or newer, just run:

ghost install
Import your data

Import your data. Copy your files. Set XXXXX permissions. Make sure it all looks reasonable.

Update Ghost to XXXXX latest version

It will prompt you to view XXXXX test page before migrating, but you don't really care about that as we have to do it anyway and it's only XXXXX test version until we sort it out and put it live.

$ ghost update
Optionally update Node.js to v12

Don't do this until you've updated your blog to XXXXX latest version. After you update node, you have to force Ghost to do another update, even though XXXXX version will be XXXXX same, just in case any of XXXXX dependencies have changed.

Update your source list with XXXXX version of Node.js you want to upgrade to and then run XXXXX install command again. It will install over XXXXX top of XXXXX old version.

$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash
$ sudo apt-get install -y nodejs
$ ghost update --force
Conclusion

In this article we saw an easy way to install Ghost on XXXXX new Ubuntu server, simply by runnin' curl -L -s https://tomssl-proxy.azurewebsites.netghost-install.sh | sudo -E bash. We also (optionally) found out perhaps more than we wanted to know about what that single command needed to do behind XXXXX scenes and why.

Next time, we'll import our old blog usin' XXXXX temporary domain and perform XXXXX final steps before goin' live (sortin' out redirects, migratin' comments, fixin' DNS entries, etc).


This page has been altered by a free Microsoft Azure proxy. Details here. See the original page here