How To Install Ghost On Heroku

  1. If you have not signed up with Heroku yet, head over to the Heroku sign up page
  2. Download and install the Heroku Toolbelt
  3. Open up your command line application and type in:
  4. heroku login
  5. Log in with your Heroku username and password
  6. Now download Ghost locally to your computer. Go to to download Ghost.
  7. Download and install git if you don't already have it. Instructions for installing git can be found here.
  8. Head over to the Node.js instalation documentation for instructions on getting Node.js installed on your computer.
  9. Next change directories to where you have downloaded and expanded Ghost in your terminal application:
  10. cd /path/to/ghost/folder/
  11. Next configuration step is to tell Heroku how to start Ghost. You can do this with a Procfile. In your local Ghost directory create a text file named Procfile:
  12. sudo vi Procfile
    and insert:
    web: npm start --production
    save and exit.
  13. Next we need to create the Heroku app and tell git where to send our repository.
  14. heroku create
    The heroku create command creates a new Heroku app where you can see and configure your site in the Heroku web interface. It also creates a new git remote which tells git where to send your files. You can verify your git remote was setup correctly by running git remote -v. Mine looks like this:
    heroku (fetch)
    heroku (push)
  15. Next we need to add a PostgreSQL database to our Heroku app:
  16. heroku addons:add heroku-postgresql:hobby-dev
  17. Now that your database has been created we need to get some details about it. Run the following command:
  18. git init
    heroku config
    This will output something similar to the following:
    From this output you can see that our database details are as follows:
    • Database URL:
    • Database port: 5432
    • Database name: d534p9pkt2g4io
    • Database username: cbwdfrgyexwhfw
    • Database password: zrP2TJjJB4Ws0pMf3EIeP3cS_x
  19. In your config.js find the database section and replace it with the following replacing host, user, password, and database with the information from the heroku config command:
  20. database: {
        client: 'postgres',
        connection: {
              host: 'database address',
              user: 'username',
              password: 'password',
              database: 'databasename',
              port: '5432'
  21. Next we need to edit the Ghost configurations, in the config.js file. Heroku assigns a port for your Node app dynamically every time it starts. The Ghost config.js assumes that the port will be constant but this setup will not work in the Heroku environment. To overcome this we can use the environment variable process.env.PORT. Heroku assigns the port number Ghost needs to listen on to that variable.
  22. Edit your config file:
  23. sudo vi config.js
  24. In your config.js file replace:
  25. host: '',
    port: '2368'
    host: '',
    port: process.env.PORT
  26. The last step we need to do is modify how Ghost stores images so that they are persistant. Heroku does not provide persistant storage for things like image uploads. With the release of Ghost 0.6.0 we now have the ability to modify where Ghost stores images. We recomend this project that allows Ghost to stores images on Amazon S3.

  27. From the root of your Ghost install run the following:
    npm install --save ghost-s3-storage
    mkdir -p content/storage/ghost-s3
    vim content/storage/ghost-s3/index.js
    Paste the following into the new index.js file you are creating:
    'use strict';
    module.exports = require('ghost-s3-storage');
    Lastly we need to tell the ghost-s3-storage plugin where to store the images: We need to add the following section to the production section of our config.js file:
    storage: {
            active: 'ghost-s3',
            'ghost-s3': {
                accessKeyId: 'aws access key from IAM service',
                secretAccessKey: 'aws secret key from IAM service', 
                bucket: 'bucket-name', 
                region: 'aws region where S3 bucket is located', 
                assetHost: 's3 bucket url' 
    If you need assitance with creating the AWS resource please review the following AWS documentation:
    Now add all the Ghost files to git so they can be pushed to Heroku by running the following commands from within your Ghost directory:
    git add .
    git commit -m "Committing all Ghost files"
  28. You now have Ghost in a local git repository.
  29. Now you are ready to deploy Ghost to Heroku:
  30. git push heroku master
  31. This process will take about a minute. It will copy all of the local files up to Heroku. Once this is done your Ghost instance is up and running on Heroku. You can connect to your Ghost instance in your web browser by running heroku open


To avoid storing your database credentials in your config.js file you can store them in Heroku environmental variables. To do this replace the database section in your config.js file with the following:

database: {
    client: 'postgres',
    connection: {
          host: process.env.POSTGRES_HOST,
          user: process.env.POSTGRES_USER,
          password: process.env.POSTGRES_PASSWORD,
          database: process.env.POSTGRES_DATABASE,
          port: '5432'

Now we just need to populate those variables with the credentials for your database. You can do that with the following commands (replacing host, user, password, database with the values from your Heroku account)

heroku config:set POSTGRES_HOST=host
heroku config:set POSTGRES_USER=user
heroku config:set POSTGRES_PASSWORD=password
heroku config:set POSTGRES_DATABASE=database

Configuring Ghost to use the Heroku environment variables could certainly avoid a situation where your config.js was committed to a public repository.

Possible Errors:

If you can not connect to Ghost try and run heroku ps to see if your instance is running or crashed. If it has crashed run heroku logs to see why. If you can't figure out why it has crashed post a comment and we will help you out.

When running git push heroku master if you get the error:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Your ssh key was probably not sent during the initial Heroku Toolset login. You can fix this with heroku keys:add ~/.ssh/ replacing the path with your actual path.