hosting ghost platform on openshift cloud

Simple steps to deploy ghost blogging platform on openshift cloud services.

What is ghost?

Ghost is a very simple blogging platform built upon node.js. It offers simplicity along with high throughput. Sqlite or mysql databases are currently supported. Mysql is preferred database for cloud hosting. Sqlite is not recommended since most cloud services like openshift and heroku rebuild the application run-time files so your sqlite file might get deleted.

Step 1

Create a node js application on openshift and git clone the repo on your local system. Also add a mysql cartridge.

Step 2

Setup rhc command line utility on your machine and note down some environment variables for your application. You will need following ip addresses and port. Also make note of your username, password and database for your mysql cartridge.

OPENSHIFT_NODE_IP
OPENSHIFT_NODE_PORT
OPENSHIFT_MYSQL_DB_HOST

Step 3

Download ghost platform from the ghost official website. Just unzip the package and replace the files on your local repo folder. Next we need to configure the ip addresses and ports on config.js file.

Step 4

Edit the config.js file for production.

The problem: We might directly put openshift environment variables on the config.js file but it didn't work for me. So I just copy paste environment variables listed using env command on ssh shell.

production: {
    url: 'http://appname-namespace.rhcloud.com/',
    mail: {},
    database: {
        client: 'mysql',
        connection: {host: '127.8.62.130',
        user: 'admin*****',
        password: '**********',
        database: 'ghost',
        charset: 'utf8'}
        },
    server: {
        // Host to be passed to node's `net.Server#listen()`
        host: '127.X.XX.XXX',
        // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
        port: '8080'
    }
},

Step 5

Normally ghost platform can be started using npm start --production using ssh shell command. But you can change package.json file to tell openshift automally start server for you by specifify main javascript file. Put inde.js as main. By default openshift uses server.js.

It looks like this

{
     ... 
 "main": "index.js"
     ....
}

Since you cant specify the node environment in package.json file, you have to tweek a little bit the index.js file. Make production the default instead of development.

Like this

// If no env is set, default to development
process.env.NODE_ENV = process.env.NODE_ENV || 'production';

Like us

See also

Persistent Ghost platform On Cloud

Some tweeks and tricks on how to persist uploaded images on ghost platform hosted on clouds.

Common SSH commands

List of some common SSH commands and SFTP commands you frequently use.

Why cloud?

Why do you need cloud hosting?

Free cloud services

You want to host start using cloud as your hosting platform, here are the few options available to start with. These cloud providers give your some free quota to start with.