Running Ghost on Heroku
September 21, 2013
Running Ghost (http://ghost.org) on Heroku is so easy, I’m suprised I didn’t find instructions already.
TL;DR
If you already know how to implement Node.js on Heroku, there is only one change to make:
In config.js:
Change all instances of:
port: 2368
To:
port: process.env.PORT || 3000
This will call the heroku dynamic port variable or if none exists, use port 3000.
Step-by-Step Instructions
Installing Node.js
Ghost requires node 0.10.* (latest stable version).
To get it visit http://nodejs.org and press ‘install’ to download the latest stable version of Node.js.
Windows The install button will download an .msi installer file. Double click this and follow the instructions to install Node.js as you would any other software. Mac The install button will download a .dmg. Install this as you would any other software.
Installing Ghost
Download the latest version of Ghost from Ghost.org. Unzip the archive to a memorable location.
Local workstation setup
Install the Heroku Toolbelt on your local workstation. This ensures that you have access to the Heroku command-line client, Foreman, and the Git revision control system.
Declare process types with Procfile
Use a Procfile, a text file in the root directory of your application, to explicitly declare what command should be executed to start a web dyno. In this case, you simply need to execute the Node script using node. Here’s a Procfile for Ghost:
web: node index.js
Edit Config.js for Heroku
In config.js:
Change all instances of:
port: 2368
To:
port: process.env.PORT || 3000
This will call the heroku dynamic port variable, or if none exists use port 3000.
Test that it works locally
Run:
foreman start
This will start Ghost locally on your workstation running on port 3000.
Store your app in Git
Let’s put it into Git:
$ git init$ git add .$ git commit -m "init"
Deploy your application to Heroku
Create the app:
$ heroku create
Deploy your code:
$ git push heroku master
Open on Heroku
Ghost should now be running on Heroku.
To load Ghost from Heroku, go to your unique Heroku URL or type:
heroku open