Ghost (and Node.js) on Dreamhost VPS
Oct 20, 2013
3 minutes read

After occasionally playing with Wordpress for a personal blog over the last few years, I decided to try something new: Ghost, which aims to be “just a blogging platform”. Following are my experiences configuring it on a Dreamhost virtual private server.

I mostly followed Ryan Powell’s guide, with one key difference: I’m not running node as root, because that gives me the willies.

  • Establish two shell accounts: an administrator and a user.
  • With the admin account:
    • Install Node.js from source: grab the tarball, ./configure, make, sudo make install.
    • Install forever: sudo npm install forever -g
  • With the user account:
    • Grab the ghost tarball and extract to a directory of your choice (e.g. ~/ghost_production), then npm install -production.
    • Copy config.example.js to config.js; update it with your own url, host, and port, paying attention to the development vs production sections (I’m just using production for now).
    • Go in to your dreamhost panel and configure the server side as you wish (e.g. with a proxy pointing a subdomain/path to a specific port).
    • Try it out with NODE_ENV=production forever start index.js. (the site should now be available)
    • When you’re done poking around, kill it with forever stop index.js.

Cronjob

The site can be made to come back up after a restart with a cronjob. First create a directory to hold log files, then create a script like this (I called mine start_ghost_production.sh):

#!/bin/sh

if [ $(ps aux | grep $USER | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
	export NODE_ENV=production
	export PATH=/usr/local/bin:$PATH
	export LOGDIR=$HOME/log_ghost_production
	cd $HOME/ghost_production
	forever start -p $HOME/forever -a -l $LOGDIR/forever.log -o $LOGDIR/ghost_out.log -e $LOGDIR/ghost_err.log index.js > $LOGDIR/script.log
fi

Mark it executable: chmod +x start_ghost_production.sh. Finally, create the cronjob with crontab -e. This will open an editor; paste in e.g. @reboot /home/user/start_ghost_production.sh >> cron.log 2>&1, save and quit. Finally, test it: reboot your VPS from the Dreamhost panel, wait a minute or so, then attempt to load your page.

Mail

When you signed in to your new Ghost instance, you were probably given a big scary warning like this:

ghost_mail_warning

This isn’t a big deal: at the moment, email is only used for password resets, and the only user is you, and you have shell access to the host. If you want to configure it anyway, the settings live in config.js. Here’s the easy way*:

mail: {
    transport: 'SMTP',
    options: {
        host: '127.0.0.1'
    }
},

Try it out by resetting your password: sign out, click the “Forgotten password?” link, etc.

* The hard way would involve authentication and a mail server, which would have the advantage that the emails sent needn’t be spoofed.


Back to posts