(Last Updated On: April 5, 2018)

This guide will demonstrate how to Install Ghost on Ubuntu 16.04 / Debian Linux distributions. The installation will be for a production blog and we’ll secure it with Letsencrypt SSL certificate and redirect all http traffic to https.

Installation of Ghost on Ubuntu 16.04 is a straightforward automated process. It will configure systemd unit for managing the blog service and generate nginx configuration files for you. The only manual task you have is to answer some simple questions during installation and test settings.

What’s Ghost?

Ghost is an open source publishing platform which is beautifully designed, easy to use, and free for everyone. It has full support for Markdown and provides an easy to use the web interface for administration purposes.

Requirements

For this setup, the basic requirements are:

  • Ubuntu 16.04 / Debian 9 – updated
  • Nginx installed and running
  • FQDN – e.g blog.domain.com
  • Node.js
  • MySQL
  • ghost user – Non-root user to manage it

Let’s go to the installation section for the requirements:

Step 1: Installing Nginx on Ubuntu / Debian

Get nginx installed on your server by running:

$ sudo apt-get update
$ sudo apt-get install nginx

Step 2: Installing MySQL DB server on Ubuntu / Debian

Ghost requires MySQL to store its data. This can be done by running the commands:

$ sudo apt-get update
$ sudo apt-get -y install mariadb-server
$ sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
character-set-server = utf8

Restart MariaDB service and secure database access:

$ sudo systemctl restart mysql
$ mysql_secure_installation

Create the database for ghost blog we intend to add:

$  mysql -u root -p

create database my_blog;
grant all on my_blog.* to [email protected] IDENTIFIED By "strongpassword";
flush privileges;

Step 3: Add User for Ghost administration

# adduser blogger
# usermod -aG sudo blogger

We’ll later use this user for all Ghost related administration.

Step 4: Install Node.js on Ubuntu / Debian

We need to have Node.js installed on the system before we’re able to start using Ghost. Install it using the commands:

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

It is stated in the documentation that NVM doesn’t work well with Ghost, you need to first uninstall it if you have it on your system.

Please uninstall nvm and any node versions installed with it:

rm -rf $NVM_DIR ~/.npm ~/.bower
unset NVM_DIR;
which node;
rm -rf {path_to_node_version}

Also look in your ~/.bash_profile or ~/.bashrc and remove any nvm lines.

Step 5: Install Ghost-CLI

We now need to install the package ghost-cli which provides ghost command.

# sudo npm i -g ghost-cli
npm WARN deprecated [email protected]: It is recommended to install Yarn using the native installation method for your environment. See https://yarnpkg.com/en/docs/install
npm WARN deprecated [email protected]: Use mz or fs-extra^3.0 with Promise Support
/usr/bin/ghost -> /usr/lib/node_modules/ghost-cli/bin/ghost
+ [email protected]
updated 7 packages in 8.876s

# sudo npm i -g [email protected]

If you install Ghost via the CLI for production, you need to have met the pre-requisites and installed ghost-cli.

Step 6: Create a new folder for Ghost Data

Please note that:

  • Installing Ghost in the /root folder won’t work and result in a broken setup!
  • Installing Ghost in your /home/{user} folder won’t work and result in a broken setup!
  • Please only use /var/www/{folder} because it has the right permissions.

So let’s create this directory:

# mkdir -p /var/www/ghost
# cd /var/www/ghost

Then let’s make the user we created earlier to own this directory.

# chown blogger:blogger /var/www/ghost
# chmod 775 /var/www/ghost

Step 7: Install Ghost using Ghost-CLI

You have to run ghost within the directory you would like to install Ghost. Also, note that the directory has to be empty.

# su - blogger
$ cd /var/www/ghost
$ mkdir blog.computingforgeeks.com
$ cd blog.computingforgeeks.com

Run the command below to install ghost:

$ ghost install
...
✔ Checking system Node.js version
✔ Checking current folder permissions
✔ Checking for a MySQL installation
✔ Checking for latest Ghost version
✔ Setting up install directory
...
✔ Downloading and installing Ghost v1.21.5
✔ Finishing install process
? Enter your blog URL: http://blog.computingforgeeks.com
? Enter your MySQL hostname: (localhost) localhost
? Enter your MySQL username: my_blog
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: my_blog
✔ Configuring Ghost
✔ Setting up instance
? Do you wish to set up "ghost" mysql user? Yes
? Do you wish to set up Nginx? Yes
? Do you wish to set up SSL? Yes
? Do you wish to set up Systemd? Yes
? Do you want to start Ghost? Yes
.....
✔ Starting Ghost
Running sudo command: systemctl enable ghost_blog-rafikihost-com --quiet
✔ Starting Ghost
You can access your blog at http://blog.computingforgeeks.com
Ghost uses direct mail by default
To set up an alternative email method read our docs at https://docs.ghost.org/docs/mail-config
  • This will install and start your blog in production mode using MySQL as the default database

Nginx configuration files will be placed under: /etc/nginx/sites-enabled/

If you chose SSL configuration, then there will be -ssl.conf file for https.

If you chose to setup systemd, then your systemd unit will be created, whose symlink is:

# ls -lh /lib/systemd/system/ghost_blog-computingforgeeks-com.service
/lib/systemd/system/ghost_blog-computingforgeeks-com.service -> 
/var/www/ghost/blog.computingforgeeks-com/system/files/ghost_blog-computingforgeeks-com.service

To manage the service with this unit, use:

# systemctl <command> ghost_blog-computingforgeeks-com.service

Some Ghost troubleshooting Cheats:

Logs dir: /content/logs/
$ ghost start: Start ghost
$ ghost restart: Restart ghost
$ ghost run: Test if the ghost can start successfully
$ ghost uninstall: Re-install ghost
$ ghost update: Upgrade ghost
$ ghost update — force: Force upgrade if there are errors
$ ghost update –rollback: Revert to the earlier version if an upgrade fails
$ sudo npm i -g [email protected]: Upgrade Ghost-CLI
$ ghost ssl-renew: Renew ssl certificate
$ ls ./system/files/*.conf: System configuration files
$ ghost setup nginx: Manually Setup nginx
$ ghost setup nginx ssl: Setup nginx with SSL

Step 8: Accessing Ghost Admin interface

Your setup is now ready, access Ghost web admin interface where you can upload themes, change settings and write content using markdown syntax.

http://blog.computingforgeeks.com/ghost

Replace the URL with your valid URL. When you are accessing it for the first time, it will ask you to create first admin user account.

In our next article, I’ll cover using markdown to writing content for Ghost and how to add themes and other customizations to Ghost website.