Ghost on Azure Web Apps

Published on Tuesday, December 15, 2015

Every so often I like to try out different blogging platforms and Ghost is one that I have looked at multiple times since the project started. Even though it has been getting easier, the experience is not great when running Ghost on Azure.

There are a number of ways you can accomplish this, everything from forking the Ghost repo and building it to hosting Ghost on a Docker container.

I decided to deploy Ghost as an NPM module for a few reasons.

  • The ability to update a version number and re-deploy without dealing with Git forks, pulls, or commits from any other repos
  • I was not going to edit the Ghost platform itself, the only changes to the site would be related to content, themes, and configuration

For some of the other ways you can host Ghost on Azure, check out this post by Andrew Zay.

Now here is the step by step guide to creating a Ghost site on Azure using NPM.

Prerequisites

  • Install NPM

  • Install Git

  • Install Azure CLI - npm install -g azure-cli

  • (Optional) Install Visual Studio Code

Setup Local Environment

  1. Create a new directory for your Ghost app

  2. Initialize an npm package with npm init

  3. Fill in the require information

  4. Add the following to package.json

    "engines": {
        "node": "0.10.32"
    },
    "dependencies": {
        "ghost": "0.7.4"
    }
    
  5. Create a server.js file

  6. Add the following

     var ghost = require('ghost');
     var path = require('path');
    
     ghost({
         config: path.join(__dirname, 'config.js')
     }).then(function (ghostServer) {
         ghostServer.start();
     });
    
  7. Create an iisnode.yml file

  8. Add the following to iisnode.yml

     node_env: production
     loggingEnabled: true
     logDirectory: iisnode
    
  9. Initialize a Git repository

Create Local Content and Config

  1. Create config.js file based on the content here

  2. Update production > url to your Azure Web App url

  3. Update production > server > port to process.env.PORT

  4. Add the content path after the server config

     paths: {
         contentPath: path.join(__dirname, '/content/')
     }
    
  5. Copy /content/ directory from here to the root directory

  6. Copy the casper theme from here to the /content/themes/casper directory (this was a sub-module so it was not included on the github zip download)

  7. Commit to Git repository

Deploy to Azure

  1. Using the Azure CLI tool create a new Azure Web App

     azure site create --location "West US" my-ghost-app --git
    
  2. Commit the new .gitignore file to your repository

  3. Push changes to Azure

     git push azure master
    

At this point the deployment script should output to the console.

The first time you hit the site, node will be running some db migrations to initialize the data store. You should be able to see the stdout or stderr logging in the site/wwwroot/iisnode sub-directory.

Note: I chose the node version and ghost version specifically. I have had issues related to node, npm, ghost, and other dependencies in the past.

Thanks for reading.