How to install Ghost blogging platform

Jul 16, 2018 4 min read
How to install Ghost blogging platform

Updated 09/06/2020 🤓

I'm going to base this guide on the official documentation where they use:

Ubuntu 16.04 or Ubuntu 18.04
NGINX (minimum of 1.9.5 for SSL)
A supported version of Node.js
MySQL 5.5, 5.6, or 5.7 (not >= 8.0)
Systemd
A server with at least 1GB memory
A registered domain name

This is the setup that Ghost CLI is intended for & tested against, and is the only setup that they guarantee will work out of the box. Ghost CLI is designed to be extensible in the near future, however if you choose to use alternatives to our recommended stack you should expect to have to debug & fix problems yourself.

Prerequisites

This guide assumes that you have the following:

  • An Ubuntu 16.04 or 18.04 server.
  • A domain name pointed at your server's public IP (I recommend using Cloudflare CDN), as per How to Set Up a Host Name. This tutorial will use example.com throughout.

Configure Server

Login as root: sudo -i
Run the following to ensure Ubuntu is up to date:
sudo apt-get update && apt-get dist-upgrade -y

You will likely be asked the following: "A new version of /boot/grub/menu.lst is available, but the version installed currently has been locally modified. What would you like to do about menu.lst?" Just press enter and choose the default, "keep the local version currently installed".

Get out of root: exit

Create a new user and follow prompts
sudo adduser arturo

Add user to superuser group to unlock admin privileges
sudo usermod -aG sudo arturo

Log in as the new user
su - arturo

Install some needed software
sudo apt-get install -y unzip build-essential libssl-dev git nginx apt-transport-https ca-certificates curl software-properties-common systemd gcc g++ make

Open Firewall for HTTP/HTTPS
sudo ufw allow 'Nginx Full'

Install MySQL
sudo apt-get install mysql-server

MySQL on Ubuntu 18.04

If you’re running Ubuntu 18.04, a password is required to ensure MySQL is compatible with Ghost-CLI. This requires a few extra steps!

To set a password, run sudo mysql

Now update your user with this password

Replace 'password' with your password, but keep the quote marks!

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

Then exit MySQL
quit

and login to your Ubuntu user again
su - arturo

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 12
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash
Install Node.js
sudo apt-get install -y nodejs

Install Ghost-CLI

Ghost-CLI is a commandline 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

Create a new folder (We'll name ours 'myBlog' in this example; you can use whatever you want)
sudo mkdir -p /var/www/myBlog

Your user must own this directory
sudo chown arturo:arturo /var/www/myBlog
Where [arturo] is the user you created during the setup phase.

Your installation folder must have the correct permissions
sudo chmod 775 /var/www/myBlog

Navigate to the new folder
cd /var/www/myBlog

Run the install process

ghost install

This will install and start your blog in production mode using MySQL as the default database. Once the install is finished you'll be able to access your new site and navigate to /ghost to access Ghost Admin ✨

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 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. Press [enter] for default. In that case the database must already exist and have the correct permissions.

Set up a ghost MySQL user? (Recommended)
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.

Set up NGINX? (Recommended)
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?

Set up SSL?
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.

Enter your email
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.

Set up systemd? (Recommended)
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.

Setup the root account:

http://example.com/ghost

What to do when an install fails

  • If an install goes horribly wrong, you can use ghost uninstall to remove it and try again.
  • If an install is interrupted or the connection lost, use ghost setup to restart the configuration process.
  • For troubleshooting and errors, use the site search and FAQ section to find information about common error messages.

If at somepoint your nodejs starts listening in a different port, check the port is using and assign it to the nginx config, check the port number with: sudo netstat -plnt

What's next?

Some configurations are requeried.

If you'd like to upload via SFTP as a quick fix non recomended uption, you can temporarly give your root user ownership to do so, first see who owns the directory:
ls -ld /var/www/myBlog/content
most likely it says ghost, now give ubuntu the power:
sudo chgrp -hR sudo /var/www/myBlog/

Now you can upload via SFTP, remember when you are done to run:

Great! Next, complete checkout for full access to ArturoFM.
Welcome back! You've successfully signed in.
You've successfully subscribed to ArturoFM.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.