Host your own WordPress Blog using a Raspberry pi 2

Convert your  35$ Raspberry Pi 2 into a WebPress Server and host your own Blog

The Raspberry Pi 2 with it’s low power consumption and small foot print makes for an ideal home/ soho server of all sorts. It’s a simple process to set it up to host you own blog  using WordPress.

A note on Security  : Sharing a website / files on the Internet requires that you make your Pi Web server to be “Internet facing” – by forwarding port 80 from your router. But before doing so, you should research and be aware of the attendant security risks and some of the measures needed to address them. A foot note at the bottom of the guide will give you a few pointers.

Overview :

  • Download the latest Rasbian
  • Prepare a SD / Micro SD card to receive the downloaded Images.
  • Un compress and Transfer the downloaded Raspbian Image to the SD / Micro SD card.
  • Install Raspbian.
  • Configure Raspbian for a static network.
  • Install  Apache Web Server
  • Install PHP and Associated Packages
  • Install MySql
  • Install WordPress
  • Configure WordPress and start blogging.
  • Configure your router to access your Webserver and a domain name that points to your webserver.

Time and Difficulty :

  • Time : Between 45 and 60 mins  once you have the Raspbian Image file and the rest of the software.
  • Newbie Difficulty level : Moderately easy ; Will need to use terminal and type in commands.

What you will need :

  • Raspberry Pi 2 Model B or one of its clones like Banana Pi M1 or M2 or Banana Pro
  • Ethernet connection or a supported USB Wifi adapter for the Pi
  • SD or Micro SD Card that fits into your Pi (4GB or above is recommended)
  • USB Keyboard and Mouse
  • Connection to a TV or Monitor

You should seriously consider :

  • Learning about SSH and how to remotely access the Pi from another machine on your network.
  • Learning about Port forwarding settings for your Router.
STEP 1 : Install Raspbian
  1. The easiest way to install Raspbian is goto the Raspberry Pi downloads page and and download Noobs.
  2.  Follow the steps described in the Noobs setup Guide to get yourRasbian running. In the initial setup page, Select Raspbian and avoid the rest of the options for this project. The default loginand password are “pi‘ and “raspberry” respectively.
  3. Change the default password of the Pi during the first boot sequence in the Raspberry Pi configuration menu.  You can always go back to the Pi configuration menu by typing in ‘sudo raspi-config‘ at the command prompt.
  4.  Complete the Setup, restart the Pi with a ‘ sudo reboot‘ command.

 

STEP 2 : Give the Pi a static IP address

By default, the Pi is set to ask for a dynamic IP address from the router. You will need to change this setting to a fixed IP address since you will be hosting a Blog on the Pi and need the address to be fixed so that the port forward from your router always points to the Pi.

Assigning a Static IP address to the Pi can either be done at the Router level (which is fairly easy but the steps to do this are router’s model and brand specific) or at the Raspberry Pi level (outlined below).

Note :  replace the x in the lines below with what appears on your screen as you type in the commands.

Log on Raspbian and enter the following commands at the terminal :

  1. ifconfig” (ifconfig displays details of your current network connection )
  2. Write down the values next to inet add:192.168.x.xxx. These numbers is the IP address that your Pi is currently at.
  3. Also write down the Broadcast Range (Bcast) and Subnet Mask (Mask) that appear next to the inet add.
  4.  To get information from your router, type in “sudo route -n“.  This will give you the gateway and destination values.
  5. Write down the Gateway = 192.168.x.x & Destination = 192.168.x.x

We have now obtained all of the data that we need to setup our Raspberry Pi with a static IP address, it’s time to save it to a config file.

Type in “sudo nano /etc/network/interfaces”  ( nano is a text editor and will open the file interfaces located in the folder /etc/network)

In nano, look for the the line that reads “iface eth0 inet dhcp”. This line is telling the ethernet “eth0” networking interface to use “dhcp” (dynamic IP). Firstly, replace “dhcp or manual” with “static”.

Next , add the following lines directly below the line you just altered, with the data you had written down earlier.

address your.chosen.IP.address
netmask your.netmask
network  your.destination
broadcast your.broadcast.range
gateway your.gateway

The file should look something similar to the image below :

staticip

Save your file and exit out of nano by pressing ctrl+x

Reboot your Pi by typing in “sudo reboot

Once rebooted, your Pi will be on a static IP address. Crosscheck this by typing in “ifconfig” again.

 

STEP 3 : Install Apache, PHP and associated Libraries

For your Raspberry Pi to serve up websites, you will need to install a webserver.  Apache is a program that listens for server access requests from Internet browsers and grants them, if permitted. So if you want anyone to be able to access a website on your Raspberry Pi—including yourself—you need to install a Web server.

To install Apache, type in “sudo apt-get install apache2 -y″

Type in the IP address of the Pi onto the browser of another computer on your network and you should see “It works!” The default landing page of Apache.

itworks

To allow your Apache server to process PHP files, you’ll need to install PHP5 and the PHP5 module for Apache.

Type in “<strong>sudo apt<span class="token operator">-</span>get install php5 libapache2<span class="token operator">-</span>mod<span class="token operator">-</span>php5 <span class="token operator">-</span>y</strong>"

 

Once all the software is installed, restart Apache by typing in “sudo service apache2 restart

Your tiny little Webserver is now humming!

The website is hosted at “/var/www/index.html” on your Pi.

You can edit the file or replace it with your own website.

 

STEP 4 : MYSQL ; DOWNLOAD AND INSTALL

We will now need to install the database engine – MySQL. During the installation process, you will be asked to create a password for root.

Enter “sudo apt-get install mysql-server php5-mysql -y” to install MySQL.wordpress1

STEP 5 : WORDPRESS ; DOWNLOAD AND INSTALL

WordPress has it’s latest version always available at wordpress.org/latest.tar.gz and wordpress.org/latest.zip. We will use the wget command to grab the latest version. Enter the following commands at the terminal :

  1. cd /var/www ” (  Go to /var/www folder)
  2. sudo chown pi: . ” (Change ownership of the folder to user pi)
  3. sudo rm *”  ( Empty the folder of all its files and contents)
  4. wget http://wordpress.org/latest.tar.gz “(Download the latest version of wordpress )
  5. tar xzf latest.tar.gz” (Extract the downloaded tarball file)
  6. mv wordpress/* .” ( Move the contents from the freshly extracted folder to the current folder)
  7. rm -rf wordpress latest.tar.gz” ( Delete the downloaded tarball file)

Setup the WordPress Data Base  by entering the following commands at the terminal 

mysql -uroot -p ( Enter MySQL with user root and enter the password at the prompt )

Once, logged in, you will see the prompt mysql>. Enter the following commands at the mysql> prompt :

create database wordpress; ( Once the wordpress database is created, you should see Query OK, 1 row affected (0.00 sec) )

Exit out of MySQL prompt by entering in Ctrl+D

Create WordPress database in MySQL
Create WordPress database in MySQL

 

Configure your WordPress installation, by opening a browser on  a PC on your network and entering the ipaddress of the Pi.

Enter the IP address of the Pi to configure WordPress
Enter the IP address of the Pi to configure WordPress

Click the “Let’s Go” button to begin configuration.

Fill out the information as per below :

Database Name: wordpress
User Name: root
Password: <YOUR PASSWORD>
Database Host: localhost
Table Prefix: wp_

Fill out the basic site information
Fill out the basic site information

You will now see a page from which you will need to copy the Highlighted text.

Copy the Highlighted text
Copy the Highlighted text

From your SSH connection, run the following :

nano wp-config.php ( Use nano to edit the file wp-config.php)

Once in side nano with the file open, Paste the highlighted text.

Inside nano, Paste the text and Ctrl+X to exit and Y to save
Inside nano, Paste the text and Ctrl+X to exit and Y to save

Now, head back to the Browser window on your PC and hit “Run the Install“. You should now see the WordPress Installation Page.

The Five Minute Word Press Installation Page
The Five Minute Word Press Installation Page

After Filling in the Forms, Click Install to complete the installation of WordPress.

Log in to your WordPress site!
Log in to your WordPress site!

 

 

STEP 6 : Pointing your Domain Name ; Handling Dynamic IP and giving access to the Pi from the world wide web.

Almost all ISPs provide a dynamic dns address to your home internet connection.  This is done for a variety of reasons – one of which is to prevent hackers from attacking a single address  consistently.

Now that you have added a host or domain into your account, we have to deal with the dynamic IP address problem. To make noip automatically update the IP address everytime your isp changes your IP address, you will need to install noip’s Dynamic Update Client.

To install the DUC on the Raspberry Pi, Enter  the following commands at the terminal :

  1. “sudo mkdir /home/pi/noip ” ( Create a folder for noip’s DUC)
  2. cd /home/pi/noip” (Change working folder to the new folder just created)
  3. sudo wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz” (Download the Software)
  4. sudo tar vzxf noip-duc-linux.tar.gz” (Extract the downloaded software)
  5. ls” (to show the newly folder created by extracting the archive)
  6. cd noip-2.1.9-1” (Change working directory to noip-2.1.9-1 or what ever is the newly created folder by the step above)

You will now need to compile and install the downloaded DUC  by entering :

  1. sudo make
  2. sudo make install (during the install process you will need to enter your email and password that you created at noip.com)

the Dynamic Update client is started by running  “sudo /usr/local/bin/noip2” .

The DUC service will now run until the Pi is shutdown.

To make the DUC startup automatically and run in the back ground, We will need write a small script that will execute at startup.

Recommend this excellent article on Techrepublic.

 

5 thoughts on “Host your own WordPress Blog using a Raspberry pi 2”

  1. Couple things:
    1) Make sure your internet provider allows port 80; many providers block the port to prevent people running web servers while on consumer plans. While you can configure to use port 81 or something else, it is non-standard and not recommended for anything that remotely has any real traffic going to it (family members only, for example).

    2) Even if the port is unblocked by your provider, ensure you are not violating terms of service by running a webserver that might get a lot of incoming traffic.

    3) Don’t use an SSD card for data storage – they are unreliable for the kind of application you’re using this for. Web servers need to be stable and operational 24×7 without hiccups. SSD cards have limited cycles and will quickly gain errors after about a year or so. Instead, buy an SSD external USB drive.

    4) Never use Apache on the pi! It is bloatware that eats up too much memory and resources on the pi’s limited abilities. Even the pi3 needs to run Nginx to be speedy enough.

    5) Remember that commercial hosting packages out there are pretty cheap & most of all, reliable. Even for hobby sites you want to ensure you get a lot of visitors, else you’ll find yourself not interested in updating it when nobody visits. So all in all, it’s cool running wordpress on the pi but not necessarily cheaper and may be more damaging in the long run.

Leave a Reply