If, like me, you’re hosting a website on your Raspberry Pi, you may have struggled finding a fast blogging engine or content management system. Over the past year, I’ve tried a number of solutions that rely on a MySQL database (such as Joomla, WordPress and Drupal) but none have been fast enough due to the amount of grunt needed to run MySQL.
I then looked at other blog/CMS software that used SQLite (including WolfCMS, phpSQLiteCMS and others) but most ran on Apache, which is also quite resource hungry. Some were able to run on Lighttpd or other smaller webservers but they still didn’t seem particularly fast. At this point I resorted to writing my own pages in HTML and PHP which were served really quickly but took ages to write.
To summarise, I wanted blogging software to run on the Raspberry PI which was:
- Served at a reasonable speed.
- Easy to write.
- Easy to maintain.
- Portable to other platforms, should I choose to move to another server.
After looking high and low for a solution, I finally came across my answer: Pelican. Pelican is a static site generator that requires no database or server-side logic. You write up the content in either Markdown, reStructuredText or AsciiDoc and Pelican creates your HTML pages for you. That’s it. Well, it does take a little setting up, but once you are set up you’re going to be really productive and serving out fast pages.
One of the easiest ways to set up Pelican is to set it up on your local machine (Linux, Mac, Windows) and then create everything on your local machine. Then, when you’re ready to publish, you can copy it across to your server. Another option is to develop on your Raspberry Pi and then update there – that’s the way I’ve chosen but, if you do go down this route, then make sure you back up your data 🙂
Regardless of whether you choose to develop locally or on the server, you’ll need to take the following steps to get up and running:
- Install a fast web server (I recommend Lighttpd)
- Install Python
- Install Pelican
- Create your site
Install the web server
Installing Lighttpd is reasonable straightforward. I like to install php too, as it gives you server side scripting possibilities, so at the command prompt, type in the following, one after each other:
sudo apt-get -y install lighttpd
sudo apt-get -y install php5-common php5-cgi php5
sudo lighty-enable-mod fastcgi-php
Once these applications are installed, you are ready to start Lighttpd with the following command:
sudo service lighttpd force-reload
Now test that your webserver is up and running by typing the IP address of your Raspberry Pi into your browser. If you’re not sure of the IP address, type:
sudo ip addr show
into the terminal and your IP address will be on the last line of the output.
Next, you’ll need to change the permissions of the webserver:
sudo chown www-data:www-data /var/www
sudo chmod 775 /var/www
sudo usermod -a -G www-data pi
Now you have installed and configured your webserver.
To get to the root directory of your webserver, type in:
To modify the configuration of the webserver, type in:
sudo nano /etc/lighttpd/lighttpd.conf
If you make any changes to the Lighttpd configuration, you’ll have to restart the server using:
sudo /etc/init.d/lighttpd restart
The next job is to install Python. Python is usually installed on Raspberry Pi machines, but you will need the dev tools too. This is done by typing the following at the CLI (command line interface):
sudo apt-get install python-dev
curl -O http://python-distribute.org/distribute_setup.py
Now you have Python installed, the next step is to install pip, which allows for easy install of Python packages. To do this, type in the following:
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
We’re also going to install virtualenv, which creates isolated environments in Python:
sudo pip install virtualenv
Now, your Python environment is all set up.
Pelican is the final piece of the jigsaw and is installed using pip. We’re also going to install Markdown which is one of the formats you can code your page in, instead of using HTML. The commands you need are as follows:
pip install pelican Markdown
Now, create a directory under /var/www/ called pelican to serve your files from. (You can give this directory any name you like, or you can install you files directly into /var/www if you like.)
Next we run the pelican-quickstart command, which will ask some questions about your site:
When you’ve answered these questions, your Pelican installation is configured and ready to go. If you need to change the configuration at any time, type in:
sudo nano pelicanconf.py
The settings that you can add or change can be found on the Pelican Docs site
Your Pelican installation on your Raspberry Pi is now set up. Your next job is to create the manage the content for your site.
Create your site
In /var/www/pelican, or wherever you installed your pelican installation, you will find a directory called content. (I’ll assume that you’ve used var/www/pelican for the purpose of this tutorial, if you haven’t, replace /var/www/pelican/ with whatever your root folder is called.) In the content folder you can create your first file, lets call it index.md
sudo nano /var/www/pelican/index.md
As you see, the extension is called .md not .html. This is because Pelican takes the .md file (Markdown file) and converts it to HTML for you. More information on Markdown can be found here. Now enter the following at the top of your file:
Title: 874 is ace!
Date: 2013-11-02 13:11
Tags: ace, 874
Author: Gary Hall
Summary: This is a test for the summary
This is the content of my first blog post.
Now save the file, exit nano and generate the html as follows:
Now, if you go to http://your.ip.address/output you will see the HTML page that you’ve generated. Well done, you’ve created your first blog page using Pelican on your Raspberry Pi!
For additional information, you can visit the Pelican documentation
If you want to change the look and feel of Pelican, take a look at the Pelican themes directory
Enjoy the experience of running a fast blog on your Raspberry Pi. Whoosh!
Published on Tue 14 January 2014 by Gary Hall in Linux with tag(s): pelican raspberry pi