How to install Ghost with NPM and Dokku

Today I installed Ghost, a blog app, on my very own server!
I installed it with dokku, a mini Heroku clone.


Installation notes

On the server, create an app

dokku apps:create blog
dokku config:set blog NODE_ENV=production

Turns out it worked best to install Ghost via npm, because it's already built.

I have it installed, but I need to setup a shared directory.

On the server, add the shared directory

dokku docker-options:add blog "-v /home/dokku/blog/shared:/app/shared"
dokku docker-options blog

So... I needed to modify Ghost and things got crazy. Turns out the npm package isn't directly what is in the repo. It contains the built files. So I had to build the files and add those to my fork (in a branch). After that, it worked!

Nice! It works! Hallelujah!

What's really nice is I have a repo that only has the bare minimum to run ghost plus a theme.

It looks like this:

/themes
   /casper
config.js
index.js
package.json
README.md

Code samples

package.json

{
  "name": "blog",
  "version": "0.0.1",
  "description": "blog.rchrd.net",
  "main": "index.js",
  "dependencies": {
     "ghost": "rchrd2/Ghost#package"
  },
  "devDependencies": {},
  "scripts": {
    "start": "node index",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Richard Caceres",
  "license": "ISC"
}

index.js

var path = require('path');
var ghost = require('ghost');

ghost({
    config: path.join(__dirname, 'config.js')
}).then(function (ghostServer) {
    ghostServer.start();
});

config.js

var path = require('path'),
    config;

config = {
  production: {
      url: 'http://blog.rchrd.net',
      mail: {},
      database: {
          client: 'sqlite3',
          connection: {
              filename: path.join(__dirname, '/shared/content/data/ghost.db')
          },
          debug: false
      },

      server: {
          host: '0.0.0.0',
          port: '5000'
      },
      paths: {
          contentPath: path.join(__dirname, '/shared/content/'),
          themePath: path.join(__dirname, '/themes')
      }
  },
  development: {
      url: 'http://localhost:2368',
      database: {
          client: 'sqlite3',
          connection: {
              filename: path.join(__dirname, '/content/data/ghost-dev.db')
          },
          debug: false
      },
      server: {
          host: '127.0.0.1',
          port: '2368'
      },
      paths: {
          contentPath: path.join(__dirname, '/content/'),
          themePath: path.join(__dirname, '/themes')
      }
  }
}

// Export config
module.exports = config;