Click here to Skip to main content
15,888,968 members
Articles / Internet of Things / Raspberry-Pi

Raspberry Pi 2: Configuring It as a Complete WordPress Web Server – Part 1

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
30 Nov 2016Ms-PL8 min read 5.6K   2  
Raspberry Pi 2: How to configure it as a complete WordPress Web Server

[Download the Complete Tutorial as a single PDF.]

I got a Raspberry Pi 2 (referred to as RasPi 2 from now) and for a while agonized over what use to put it to. I looked through projects others have done. These ranged from robotics and drones to media servers and home automation. The most interesting one I found was for a digital mirror (I still might do this one some day). What I have been wanting for quite sometime now is a cheaper system to take over mundane low-power tasks like DNS and hosting my WordPress websites. The RasPi 2, made an excellent choice for that need.

I have the following running, but on a Windows system — DNS, IIS with PHP and MySQL server. My task was to move out all of this infrastructure to the RasPi 2. I first did a dry run to see what I could and could not do. I ended up corrupting the configurations so badly that I rebuilt the RasPi 2 from scratch. This article is post that rebuild, with experience and expertise gathered from both runs.

Before You Begin

The RasPi 2 is a headless device and comes without a keyboard or mouse. So you need all of them to be able to use it. It has a 1Gbps Ethernet port that will come in handy a little later. For now, you need a HDMI monitor, a USB keyboard and a USB mouse. There is no need to connect it to a network or the Internet on first boot, but keep it that way from the start if you can.

Unboxing and Initial Configuration

My kit came in a packaged box not much larger than you would expect for a conventional external hard drive. The RasPi 2 device itself is very small. It fits into the palm of your hand (less than 15cm long and about half as much wide). The core device is just a PCB. So make sure you get a case for it. The Kit I referred to above has a bundled case (I got the clear case, but there is also a black / opaque case). The Kit provides a 16gb (or 8gb optionally) Class 10 SD card. This is the primary storage (“hard disk”) for the system. You can attach more storage via USB later on. And yes, there are 4 USB ports and 1 HDMI port. Power is supplied using a micro-USB port that will fit a modern spec mobile charger. A 100/1Gbps Ethernet port provides networking. There is no Bluetooth or WiFi built-in, though you can add them via USB adapters. All the required cables and cards and boxes are bundled in the kit. Note that this kit also contains a component cable that I did not use.

Note: The USB ports are un-powered. Therefore, if you attach things like USB hard disks, make sure you are using those that have a separate power system to get their power (that is, they cannot get electric power from the RasPi).

First up, I wanted to see if the thing works. So I connected them all up (it is quite easy to just snap things in), connecting the system via HDMI to my Samsung Smart TV and powered it on. At first, absolutely nothing happened. The LED power light on the RasPi glowed. So it had power. But nothing on the display. After a while of looking and staring, I decided it was time to RTFM. Then I noticed that I had stuck the SD card into the wrong slot. It so happens that the RasPi has its own micro SD slot (on the end opposite to where the USB ports are) and the kit gives you a micro-USB adapter that you can plug into the standard USB ports. I had used the adapter. Once I switched the SD card to the right slot, it booted up into NOOBS. Satisfied it was working OK, I disconnected everything and headed off into my den.

Installing the OS via NOOBS

You need a monitor, mouse and keyboard directly attached to RasPi 2 through the below steps. I’ll tell you when it is safe to move to a remote terminal shell.

NOOBS stands for “New Out Of Box Software”. It is basically a GUI shell that lets you pick and install an OS of your choice to the RasPi. It comes bundled with several flavors of Linux. Don’t worry about the warnings that everything would get wiped out — NOOBS will still work and you can still manage to go to a different OS on the list or re-install from scratch even if you re-partition the SD card. I picked the first two options on the list: Install Raspbian OS and to re-partition everything else on my SD card into a data partition.

It takes about 5-6 minutes to install the OS. Once done, the system will reboot and drop you into something called “raspi-config”. This is a text-based configuration UI like you see below:

raspi-config

Raspi-Config

Reminds one of the “linux-config” (what was it called “Menuconfig” ?) that used to exist a long time ago, right? But this is way way … way less powerful. As you can see, its options are quite limited. You will want to do the following:

  • Change User Password – This will change the password for the “pi” user. The default password is supposed to be “raspberry”, but you want to definitely change it.
  • Enable Boot to Desktop/Scratch – I went to this option and selected to “Console” (this drops you into the BASH command shell).
  • Go into Internationalization options and select your system locale, timezone and such. You will need to keep returning to the option to finish all three (Local, Timezone, Keyboard layout). The default location is set to English (UK).
  • The final option you want to do inside “Advanced Options” and you want to set the “hostname” here (second option from top).

When you are through, hit the “<Finish>” at the bottom. This will drop you into the BASH prompt.

Root

Immediately, change the root password. There is no default password for root:

$ sudo passwd root

sudo” is required since you are currently logged on as “pi”. Set a strong password for root.

Personally, I hate “sudo”. It is like cheating on myself. I prefer to be straight root. So once I changed the “root” password, I hit CTRL+D (shortcut to logout) and logged in as root.

NOTE: From this point onwards, I am doing things as “root”. Hence note the “#” prompts and lack of “sudo”.

Set Date/Time

I found that the RasPi 2 I got had a time problem. Basically, its time is set to way back in the past. So the next thing to do is to run the command:

# date --set="2015-05-10 10:15:06"

Remember to set the date and time to the correct values (the part in bold as per your current date and time).

You need RasPi to be connected to the Internet from this point onwards! If you plugged it into a DHCP-powered system, chances are it is already online. Try by running “ping www.google.com” at the prompt.

Update

The version of any OS bundled on the SD card is bound to be quite old. So, the next thing to do is to run updates. I prefer APT, if you find some other package manager gives you the goosebumps, go with that.

# apt-get update

# apt-get upgrade

The first command updates the locally cached package information. The second command downloads all the required bits to perform the update itself. During the upgrade run, you will be prompted to proceed, answer by pressing “y” and then ENTER.

Once it is updated, though the system will never tell you (Linux never asks you to reboot it in my over twenty years of experience with it!), reboot it. It is nice to reboot the system before the next steps so that everything is in a stable and sane state.

Tools You Will Need On Your Windows System

To be able to manage your RasPi from your Windows system, you will need the following tools:

  • PuTTY. This is a remote terminal shell. It will give you command prompt access using a variety of ways. Download from www.putty.org. There is nothing to install – if you get a ZIP file, extract the “putty.exe” to a folder and create a shortcut to your desktop. To connect, simply enter the IP address of your RasPi in the Hostname or IP address textbox, leave the port at 22 and click the “Open” button.

    putty

  • WinSCP. Download this tool from http://winscp.net. It provides easy file transfer and management capabilities for Linux systems. One great feature of this tool is that it lets you edit Linux files on Windows in a clean way — this is important because of a key difference between how Linux and Windows manage the characters that control where a “line” ends in a file. You will need this later on.

This article has become quite long, so continue reading in Part 2 where we pick up after the reboot and install and configure BIND and also transfer our Windows zones to it!

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --