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
Create a new directory for your Ghost app
Initialize an npm package with
npm init
Fill in the require information
Add the following to package.json
"engines": { "node": "0.10.32" }, "dependencies": { "ghost": "0.7.4" }
Create a server.js file
Add the following
var ghost = require('ghost'); var path = require('path'); ghost({ config: path.join(__dirname, 'config.js') }).then(function (ghostServer) { ghostServer.start(); });
Create an iisnode.yml file
Add the following to iisnode.yml
node_env: production loggingEnabled: true logDirectory: iisnode
Initialize a Git repository
Create Local Content and Config
Create config.js file based on the content here
Update production > url to your Azure Web App url
Update production > server > port to
process.env.PORT
Add the content path after the server config
paths: { contentPath: path.join(__dirname, '/content/') }
Copy /content/ directory from here to the root directory
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)
Commit to Git repository
Deploy to Azure
Using the Azure CLI tool create a new Azure Web App
azure site create --location "West US" my-ghost-app --git
Commit the new .gitignore file to your repository
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.
Comments