Setup Node.js and Ghost on a Raspberry Pi server

Posted by Frederik Bærentsen on 3rd Apr 2015

After using Rapidweaver for years I got fed up with the bad blog plugins. The look of the published posts was bad and the editor was not fun to work with. Rapidweaver is by no means a bad piece of software, it is by far my favorite OS X application, but the blogging functionality had something to wish for. I decided to try and look for different blog tools that utilize Markdown. I’m a huge fan for markdown and most of my writing is done in markdown (using Mou. I found the Node.js blogging tool called Ghost and decided to try it out, but it ended up being more of a challenge than first anticipated.

Getting Node.js on the Pi

Assuming you have a fresh Raspbian installation you need to download Node.js and compile it.

cd       
wget http://nodejs.org/dist/node-latest.tar.gz       
tar -xzf node-latest.tar.gz      
cd node-v0.12.0      
./configure      
make         
sudo make install        

This seemed like an easy way to do it, but after compiling for six (6!) hours on the RPi B+ I got the error with the snapshot.cc file and the compile stopped. Looking around I found a suggestion to configure using ./configure --without-snapshot, so I did that and recompiled without errors. Phew only 7/8 hours used now. But when testing the npm installation (using npm -v) I got the error: Illegal Instruction. So instead of compiling myself I decided to get a precompiled version from http://node-arm.herokuapp.com.

wget http://node-arm.herokuapp.com/node_latest_armhf.deb         
sudo dpkg -i node_latest_armhf.deb       

This ran without problem and just took 5-10 minutes and both node -v and npm -v worked without problems.

Getting Ghost on the Pi

First thing to do was downloading

wget https://ghost.org/zip/ghost-latest.zip      
unzip ghost-latest.zip -d blog       
cd blog/         

Change the server and port under production to your Pi’s IP (server) and 80 (port).

server: {        
    host: '192.168.1.5'          
    port: '80'       
}

Also change the email setup as explain in the support documents. When the email and server is setup run:

sudo npm install --production

This gave me an error telling me to run sudo npm install --production again. When it finished running for the second time I could finally run npm start --production and the server started. Going to http://192.168.1.5 showed me the blog.

To configure the blog you need to go to http://192.168.1.5/ghost and enter your details. I tried to add a user and log in but nothing kept happening. So after the letting it load for about 5 minutes it finally logged in. This is apparently a known problem, so I found out that if you replace bcrypt we could speed the process up.

cd ~/blog       
sudo npm install bcrypt      
sudo nano core/server/models/user.js         

Look for the line that looks like bcrypt = require('bcryptjs') and replace it with bcrypt = require('bcrypt'). This exchanges the bcryptjs with the new bcrypt and speeds up the login process a lot.

Now being able to log in and post worked great. The blog was live at my local network but not accessible from the outside. I forwarded the ports on my router and it didn’t work. I couldn’t get access to the ports I wanted and realized that my ISP probably blogs incoming connection on port 80. I live in a dorm room and they probably don’t want us to host web servers in our rooms.

What to do now?

I have my website hosted at http://one.com and I’ve been using them for years but they only supports php and not node.js. This is unfortunately so after exhausting all my options (and using close to 20 hours getting Ghost to work) I decided to go back to WordPress. I’ve never been a fan of WordPress, I started using it back in 2010 when I moved my website from iWeb to WordPress but quickly gave it up for Rapidweaver. What I was looking for in Ghost was the ability to write in Markdown. I found out that WordPress actually have a plugin for markdown called Splitdown and a Ghost-like theme called Casper. The combination of the two is what you see right now as my website. It is not optimal but for now it will do and I’m satisfied.