Setting up Ghost on a MediaTemple DV4

Setting up Ghost on a MediaTemple DV4

After backing Ghost on Kickstarter and getting my copy of it (Yes, I know it's been released to the public already), I thought I'd share how I got it all set up and running on my MediaTemple DV4.0. Actually wasn't that difficult.

Step 1: Install Node.js

I followed these instructions by David Seah as I've never worked with Node.js before. I only went through the CodeSchool Node.js course that was included in my Kickstarter Backing package.

Only one thing I'd note here: Make sure you download the latest version of Node by heading over to the Node.js download page. Then use the link you grab from there during Mr. Seah's wget line.

I stopped following the tutorial after I successfully dumped out Node's version to the command line. I figured it was working well enough at that point.

Step 2: Create a Site

Jump into your plesk install and create a new site. Either use a Top Level Domain (TLD) you've just had sitting around, or create a subdomain. I opted for the subdomain route. Way cheaper. Take note of where you're putting the document root. I'll be using ghost.jeffreymeagher.com as my subdomain throughout these steps. I entered ghost.jeffreymeagher.com into the little document root box while setting this up.

Step 3: Install Ghost

Download the latest Ghost and get the zip file on your server (use sftp, ftp, or wget.) Keeping it as a zip file will greatly lower the time it takes to upload to your server.

Extract the archive to a new directory you made. For me, that consisted of these command-line steps. NOTE: this is not in the same location as the webroot that was created in step 2.

  1. cd /var/www/vhosts/jeffreymeagher.com
  2. mkdir ghost
  3. cd ghost
  4. unzip /root/ghost-0.3.3.zip

Step 4: Configure Ghost

Now that it's all extracted, we need to set it up. Make sure you run (as directed in ghost's documentation) the install command to get all the extra node.js bits that ghost relies on. npm install --production

I had a few erros when node tried to install sqlite drivers. I was fine with that, since I wanted to hook this up to MySQL anyway. In the ghost forums they tell you exactly what you put in your config.js file. Here it is for easy viewing. Just replace the current database lines with these:

database: {
	client: 'mysql',
    connection: {
    	host: 'localhost',
    	user: 'root',
    	password: 'p@s$word',
    	database: 'ghost-dev',
    	charset: 'utf8'
	}
}

I also took the time to configure my email settings as outlined in the ghost install documentation.

Step 5: Configure Apache

Since the requests on port 80 (normal http port) are handled by Apache, we need a way to pass that request from apache to Node.js. Apache's ProxyPass is the answer.

Find your newly created (sub)domain's conf directory. Typically it's inside the (sub)domain's folder at /var/www/vhosts/. NOTE: this does not have to be in the same place as the document root you created in step 2. For me, it was at, /var/www/vhosts/ghost.jeffreymeagher.com/conf/ Now you can start with these steps.

  1. Create vhost.conf if it does not exist

     touch vhost.conf
    
  2. Edit vhost.conf to change the DocumentRoot and add ProxyPass directives:

     vim vhost.conf
    

Then paste the following in, as derived from this post

	DocumentRoot /dir/path-to-extracted-ghost-root
	ProxyPass / http://127.0.0.1:2368/
	ProxyPassReverse / http://127.0.0.1:2368/
	ProxyPreserveHost On
  1. Rebuild the site configuration:

     /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain ghost.jeffreymeagher.com
    

Step 6: Start Ghost

For a quick ghost start, just to test that your settings are correct, you can go to the ghost root /var/www/vhosts/ghost.jeffreymeagher.com/ghost/ and type

npm start --production

This basically temporarily fires up ghost so you can check your work. Hit up the (sub)domain with your favorite broswer and see if it works. If it does, you'll see Ghost. If it doesn't, you'll either see a 500 error (meaning some configuration is wrong), or you'll see the Apache default page. Go back and check your work.

Step 7: Start Ghost Forever

I followed this simple guide to get ghost to start forever using forever. Unfortunately I couldn't get the thing to work with an init script, so if I ever shut the server down, I'll have to remember to bring Ghost back up with forever!

NODE_ENV=production forever start index.js

Upgrading to ghost 0.4 from 0.3.3

ghost 0.4 needs python 2.7+. Unfortunately media temple's DV4 only has 2.4.x on it. So you'll need to remember to tell node to use python 2.7 that you installed in the steps outlined by David Seah. For a shortcut, simply paste this in the terminal and run it.

export PYTHON=python2.7