Hostingheaderbarlogoj
Join InMotion Hosting for $3.49/mo & get a year on Tuts+ FREE (worth $180). Start today.
Advertisement

Run the Ghost Blogging Software on a Raspberry Pi

by
Gift

Want a free year on Tuts+ (worth $180)? Start an InMotion Hosting plan for $3.49/mo.

In this tutorial I will show you how to host a blog on your Raspberry Pi using the Ghost blogging platform. Ghost is a brand new piece of blog software, currently under development which was recently funded by a Kickstarter campaign. Similar to the way Wordpress is distributed, you can opt to purchase a hosted blog or download the software to try out yourself.

As Ghost is very new it is still quite simplistic, and this simplicity makes it ideal to run on a Raspberry Pi. You'll be able to write and edit posts and upload images to your blog. I'll also show you how to install google analytics so you can see how many people are reading your website.

Prerequisites

You'll need

  • a Raspberry Pi, model A or B running Raspbian
  • a basic understanding of using the console

Setting Up Your Raspberry Pi

The next steps all use the Raspberry Pi’s command line – this is the first thing you see after the Pi has booted up. If you’re running the Pi’s desktop you can access the command line by running the console app.

In order to test the Ghost blog once it's installed, it is necessary to find out the IP address of your Pi. If you haven’t already, make sure your Pi is connected to your home network – either with the ethernet cable, or with a WiFi adapter.

Run ifconfig to find out the IP address of your Pi:

ifconfig

This will display some information about how your Pi is connected to the network — for example:

eth0 Link encap:Ethernet HWaddr b8:27:eb:39:3e:7b
inet addr:192.168.1.93 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:95549 errors:0 dropped:0 overruns:0 frame:0
TX packets:17775 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7387491 (7.0 MiB) TX bytes:20279618 (19.3 MiB)

The information you’re looking for will start inet addr:192.168.1. followed by a number – in the example above the IP address of the Pi is:

192.168.1.93

Make a note of the number, if you reboot your Pi this number will change so you’ll need to go through the steps again to find it. In this tutorial I’ll refer to this number as 192.168.1.n.

Tip: you can follow the steps in the tutorial, 'Take control of Your Raspberry Pi using you Mac, PC iPad or Phone' to set up your Raspberry Pi to work over your home network and provide it with a static IP address, then you will not need to repeat these steps every time you reboot your Pi.


Install node.js

First node.js must be installed: in the terminal type:

sudo wget http://nodejs.org/dist/v0.10.5/node-v0.10.5-linux-arm-pi.tar.gz
cd /usr/local
sudo tar xvzf ~/node-v0.10.5-linux-arm-pi.tar.gz --strip=1

To test that node has installed correctly type:

node –v

This should return the version number v0.10.5


Installing Ghost

Next I'll create a directory to install into:

sudo mkdir ghost
cd ghost

For the next step  download and install ghost-0.3.1 from the Ghost website – you will need to log in and create and account. You can do this using the Midori web browser on the Pi's desktop, or from another machine. Save the zip archive ghost-0.3.1.zip in the ghost folder you've created.

Unpack and install ghost:

sudo unzip ghost-0.3.1.zip
sudo npm install --production
sudo npm start

The second two steps take a few minutes to run, so be patient and don't interrupt the process.

Once your Ghost blog is running, you should see the message

Listening on 127.0.0.1:2368
Url configured as: http://my-ghost-blog.com
Ctrl+C to shut down

Next open a browser on the Pi and enter the address:

http://localhost:2368/

and all being well you should see an intro page:

The default Ghost blog screen
The default Ghost blog screen

Accessing Your Ghost Blog Over Your Local Network

The built in browsers on the Pi are a bit slow for blogging (particularly via a VNC connection) so to speed things up you can access your blog over your local network, Ghost also works well on a tablet or smart phone.

If Ghost is still running press the Control and C keys, simultaneously, in the terminal to shut down.

In the /ghost directory edit the < strong >config.js file.  You will need to edit this file using the IP address you found in the very first step, or the static IP address of your Pi if you have set it up to use one.

sudo nano config.js

This will launch the nano text editor - use the cursor keys to look for this text:

server: {
// Host to be passed to node's `net.Server#listen()`
host: '127.0.0.1',
// Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
port: '2368'
}

replace host: ’127.0.0.1′ with host: ‘<your IP address>’ and port: ’2368′ to port: ’80′.

Control X to exit and answer yes and press enter to write out the file.

Enter your Pi’s IP address onto another computer on your network – you should now see your Ghost blog.

Note that if you want to view your Ghost blog on your Raspberry Pi itself, you will now need to use the same address instead of localhost.


Login and Edit Your First Blog

Now you have Ghost up and running, you can start writing. To edit your blog, you login by entering the following address:

http://(your PI's IP address)/ghost/signup/

Enter your name and email address, along with a password.

Tip: Note that that there is a delay of 60 seconds between clicking the sign up button, and Ghost loading the edit screen.

Once you have created an account, you will see the default edit screen:

Editing a Ghost Blog
The Ghost edit screen

To get started click on the pencil edit icon in the top right hand corner and have a go at editing the post. Ghost includes instructions on using markup and adding images.


Publish Your Ghost Blog on the Web

If you want to make your Ghost blog accessible to the web, and don't have a broadband account with a fixed IP address you can use a service called No IP to point a domain name at your blog. Most ISP’s use dynamic IP addresses which are assigned each time you connect to the internet so NoIP uses a program that runs on the Pi to update where the hostname is pointing.

You’ll also need to open a port in the home router to allow connections to the Pi.

NoIP offers a free service with free domain names, but you can also opt for a paid account with your own hostname. Bear in mind that your blog will be reliant on your home broadband connection and that this setup is not suitable for a high traffic website.

First sign up for an account at noip.com - there is a free option available, or you can opt to pay $15 a year for a service with more features.

Add a Host, and choose a Hostname from the list of options. Then choose the DNS Host (A) option and save. The settings I’ve been using are below.

No IP configuration

Next, on the Pi download and install the noip software:

Whilst installing it will prompt you for your noip.com login details.

Finally you need to open a port in your router to allow traffic through –- there is a port forwarding guide for most routers available here – typically opening the Router’s configuration in your browser, finding the advanced menu and adding the local IP address of my Pi 192.168.1.n and HTTP Server (World Wide Web) to the forwarding option.


Keep an Eye on Your Blog With Analytics

At time of writing, the Ghost blogging software dashboard has yet to be implemented; in the longer term this will provide feedback about who is reading your blog.

In the meantime there are two services that you can use to keep an eye on your blog, and measure the number of people reading your posts.

UptimeRobot is a free service which measures the response time of your website, and can alert you if it stops responding. Sign up for an account and choose the http(s) option, and just enter the address of your blog. Over time UptimeRobot will generate a graph of your website's response time:

Ghostpi.org response time tracked on UptimeRobo
Ghostpi.org response time tracked on UptimeRobot

For more detailed statistics you can add Google analytics to your blog. You will need to sign up with a free google analytics account and create a profile.

You will need to edit a file in the Ghost directory - you can either do this in the Pi desktop, or on the command line using:

cd /usr/local/ghost/content/themes/casper

The file you need to edit is default.hbs

nano default.hbs

Search for the footer text - it looks something like this:

<footer>
<a href="{{@blog.url}}/rss/"><span>Subscribe!</span></a>
<div>
<section>All content copyright <a href="/">{{@blog.title}}</a> &copy; 2013 &bull; All rights reserved.</section>
<section>Proudly published with <a href="http://tryghost.org">Ghost</a></section>
</div>

Then add the google analytics javascript code just after the </div> tag.


Conclusion

In this tutorial I have shown you how to host a Ghost blog using a Raspberry Pi, make it available on the web and add some analytics. Ghost is an interesting introduction to hosting websites using node.js, and provides a useful way of enabling your Pi to publish information on the web.

Advertisement