How to install Ghost publishing platform on your production server

Chi Thuc Nguyen
4 min readAug 3, 2018

For full setup docs, refer: https://docs.ghost.org/v1/docs/install

This tutorial uses following stack:

  • Ubuntu 18.04
  • MySQL
  • nginx 1.10.3
  • systemd
  • Node v8 LTS (higher versions are not supported yet)
  • VPS: 2 CPU Core, 2GB RAM

Install nginx, MySQL

Update package list

sudo apt update

Update installed packages

sudo apt upgrade

Install nginx

sudo apt-get install nginx

Open Firewall for HTTP/HTTPS

If ufw was activated we need to make sure that the firewall allows HTTP and HTTPS connections.

sudo ufw allow 'Nginx Full'

Verify it works

Open your browser, try to access http://{your-server-ip}

Install MySQL

sudo apt-get install mysql-server

Install Node.js 8 LTS

Add Node.js PPA

sudo apt install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

Install Node.js

sudo apt install nodejs

Verify installed version

$ node -v
v8.11.3
$ npm -v
5.6.0

Install Ghost-CLI

sudo npm i -g ghost-cli

Verify it works:

ghost help

Install Ghost via the CLI

Create a new folder

sudo mkdir -p /var/www/ghost

Your user must own this directory

sudo chown $USER:$USER /var/www/ghost
chmod 775 /var/www/ghost

Install Ghost and follow instruction

cd /var/www/ghost
ghost install
  • This will install and start your blog in production mode using MySQL as the default database
  • If you want to install Ghost with Sqlite3, please read how here
  • Checkout our detailed prompts guide, which explains all the questions you’ll be asked during install.

Then, access Ghost admin interface to create your Ghost admin account.

http://{your-ghost-url}/ghost

When an install fails

If an install goes horribly wrong, you can use ghost uninstall to remove it and try again.

Using ghost uninstall is preferable to deleting the folder, as it will ensure there are no artifacts left behind.

Config file

Config file locates at /var/www/ghost/config.production.json:

{
"url": "http://{your-url}",
"server": {
"port": 2368,
"host": "127.0.0.1"
},
"database": {
"client": "mysql",
"connection": {
"host": "{db-host}",
"user": "db-user",
"password": "db-password",
"database": "db-name"
}
},
"mail": {
"transport": "Direct"
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "/var/www/ghost/content"
}
}

More on this: https://docs.ghost.org/v1/docs/config

Email config

Mailgun

Head along to mailgun.com and sign up for an account. It’s free to use up to 10.000 emails per month. After signing up with Mailgun, verify your email address and log-in to your account.

You need to add an domain and verify it by adding some DNS records. TXT records are enough to send emails.

After verifying, the domain status will be active, get SMTP credential from Mailgun admin interface:

And edit the email section of config file:

"mail": {
"transport": "SMTP",
"from": "no-reply@{your-domain}",
"options": {
"service": "Mailgun",
"auth": {
"user": "{mailgun-SMTP-Login}",
"pass": "{mailgun-SMTP-Password}"
}
}
},

Then verify that it works by Invite some people to your blog, from the Team menu in Ghost admin interface.

Adding Google Analytics

  1. Find and copy your Google Analytics Tracking Code from within your Google Analytics account
  2. From within your publication, go to Settings > Code Injection from the admin menu
  3. Paste the tracking code into the Blog Header section of the Code Injection settings
  4. Click Save.

Adding Disqus comment

  1. Head over to http://disqus.com/admin/create/ and fill out the form:
  • Site Title: Enter the name of your website
  • Disqus URL: This is automatically set based on the site name but you can also customize it.
  • Category: Choose a category that best describes your website.

2. The next page will display a list of popular CMS which have plugins for easy integration, select Ghost (or Universal Code option if no such option for Ghost). Copy and save the code provided.

3. Edit file content/themes/casper/post.hbs, add the pasted code between a {{#post}} and closing {{/post}} block.

4. Change PAGE_URL to "{{url absolute="true"}}"

5. Change PAGE_IDENTIFER to "ghost-{{comment_id}}"

6. Save your changes to the post.hbs file and restart Ghost with ghost restart command.

Maintaining and troubleshooting

Most administration tasks can be done using Ghost-CLI (ghost command). Use ghost help for list of available CLI commands.

More info at https://docs.ghost.org/v1/docs/troubleshooting

--

--