Cloud Hosting: IBM Bluemix

Blake Callens edited this page Feb 27, 2015 · 6 revisions

Bluemix is IBM's on demand, cloud hosting platform. Within a few minutes you can have a PencilBlue instance up and running on Bluemix with your custom domain.

Create a Bluemix account and install the cf command line interface

Go to bluemix.net and sign up for an account. Then go to the Cloud Foundry CLI Github repository and download the appropriate installer for your operating system. Once cf is installed, you'll be able to push your application up to Bluemix.

Create an app in Bluemix

On the Bluemix dashboard, click "Create an App". You'll be taken to the package selection screen, where you will select the runtime of "SDK for Node.js". Give your application a unique name and URL prefix (host), then click "Create".

Add a MongoDB service

You'll now be taken to your new app's dashboard. Click on "Add a Service" and select "mongodb" from the Data Management section. You don't need to edit the name of your database, but you can if you like. Then click "Create".

Back at your app's dashboard, you'll be asked to restage your app. Do so.

Now that you have a MongoDB service attached to your app, click on its "Show Credentials" link and copy the following items: username, password, db and url. These will be used in your PencilBlue config file.

For the url variable, remove the authentication information and add a forward slash at the end.

"mongodb://8a235ce2-d55d-4659-99a0-58997af0504c:6a6bba3d-3d20-409b-842c-52a3183f05aa@50.23.230.148:10008/db"
// Should become:
"mongodb://50.23.230.148:10008/db/"

Install PencilBlue on your computer

Important: If you have not installed the pencilblue-cli to your system, follow the instructions for your operating system here.

Open a terminal, cd to the folder you want the PencilBlue folder to reside in, and run pencilblue install.

Enter the following when prompted (replace items in brackets with your own content):

site name: [your site's name]
site root: [your site's URL]
site IP: 0.0.0.0
site port: 8080
MongoDB URL: [your edited MongoDB url from Bluemix]
database name: [your db variable from Bluemix]
Do you want to install Bower components: N

Prepare PencilBlue for Bluemix

Once the installation is complete cd to the pencilblue directory and open config.js. Remove the line "sitePort": 8080, since Bluemix will assign a port number and PencilBlue will automatically pick it up.

Add the following authentication element to the "db" section of config.js:

"authentication": {
    "un": "[your MongoDB username from Bluemix]",
    "pw": "[your MongoDB password from Bluemix]"
},

Your config.js file should now look something like this:

module.exports = {
    "siteName": "PencilBlue Bluemix Demo",
    "siteRoot": "http://pbbluemixdemo.mybluemix.net",
    "log_level": "info",
    "db": {
        "type": "mongo",
        "servers": [
            "mongodb://50.23.230.158:10008/db/"
        ],
        "name": "db",
        "authentication": {
            "un": "8a235ce2-d55d-4679-99a0-58997af0504c",
            "pw": "6a6bba3d-3d20-409b-843c-52a3183f05aa"
        },
        "writeConern": 1
    },
    "cache": {
        "fake": true,
        "host": "localhost",
        "port": 6379
    },
    "settings": {
        "use_memory": true,
        "use_cache": false
    },
    "templates": {
        "use_memory": true,
        "use_cache": false
    },
    "plugins": {
        "caching": {
            "use_memory": true,
            "use_cache": false
        }
    },
    "siteIP": "0.0.0.0"
}

Create a Procfile

Create a file name Procfile in the PencilBlue root directory and add the following to it:

web: node pencilblue.js

This will tell Bluemix what to run to start the PencilBlue application.

Deploy PencilBlue to Bluemix

From your PencilBlue directory, run the following in a terminal, where [your app name] is the name of your Bluemix app:

cf push [your app name]

When the process is complete, your PencilBlue site should be up at [your app name].mybluemix.net.

Adding a custom domain

If you want your PencilBlue site to live at a domain other than mybluemix.net, then you'll need to add your domain to the app.

From your Bluemix dashboard, open the organization dropdown (the sitemap icon) in the top left and click "Manage Organizations". Go to the Domains tab and add your custom domain.

Change your domain's DNS settings to have a CNAME record pointing to [your app name].mybluemix.net. Your website should be up and running on the new URL.

Troubleshooting

If your application fails to launch check the logs with cf.

cf logs [your app name]

The most common errors are invalid JSON in the config file or incorrect MongoDB credentials.