Web server on raspberry pi – how to setup?

Introduction

In this post I will let you know how to set up web server on raspberry pi. There are many web servers for raspberry pi. In out example we will be setting up apache web server. Apache is a popular web server application and we will install it on raspberry pi to server web pages

 Step 1 -Install APACHE

First install apache 2 package by using the following command in to the terminal

sudo apt-get install apache2 -y

 Step 2 – Test the Web Server

By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/ on the Pi itself, or http://192.168.1.9 ( IP address of Pi) from another computer on the network.

Browse to the default web page either on the Pi or from another computer on the network and you should see the following:

default_html_page

This means you have Apache working!

Step 3 – Changing the default Page

This default web page is just a HTML file on the filesystem. It is located at /var/www/index.html.

Navigate to this directory in the Terminal and have a look at what’s inside:

cd /var/www/html

ls -al

This will show you:

step3_htme_page_location

Step 4- Install Php

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

 sudo apt-get install php5 libapache2-mod-php5 -y

Now remove index.html file and add index.php with following content

<?php echo "hello world"; ?>
<?php echo date('Y-m-d H:i:s'); ?>
<?php phpinfo(); ?>

Now open the index.php page. You will get following:

dynamic_php_page

You are now done setting up web server on raspberry pi which can server dynamic pages.

In the next post we will use this web server to post real time data from arduino/raspberry pi and also control different appliances from the web page.

Raspberry Pi 2 Pinouts

In my earlier blogs I have shown you how to install the OS and use it. Now we are ready to start building the projects. To do so we first need to understand what each pin does. The diagram below shows raspberry pi 2 pinouts and what each pins can do.

rapberry pi 2 pinout 1

Raspberry Pi 2 pinout figure 1

In order to understand pin number, make sure to have your pi oriented as shown in the figure. Now look at the centre two columns on the chart. These shows the Physical Pin number. The outer two columns of the chart show you the bcm numbering. The numbering system that you use depends on how you configure things in the software. There are 2 numbering sachems. One is BCM(Broadcom)

which is more common and will be using for most of the projects and the other is  WiringPi. The picture below shows WiringPi numbering.

raspberry pi2 pinout 2

Also you can notice that some of the pins are multi-purpose. For example pin3 and 5 can be GPIO pins, or they can be configured for I2C. Similarly, 8 and 10 can be General purpose or can be Tx and Rx. Also note that the GPIO pins are analogous to your digital input/output pins on Arduino.

 

 

Raspberry Pi 2 pinout figure 2

 

 

Raspberry Pi XBMC Media Center

In this project I will let you know steps to make your own Raspberry Pi XBMC Media Center.

Parts Required
The parts you will you need for this project are listed below. You will probably only need a USB keyboard and mouse for the setup after this you can remotely control XBMC (Kodi) via a tablet and/or web browser.

  • Raspberry PI
  • 4 GB SD Card (8 GB+ Recommended) or Micro SD Card if you’re using a Raspberry Pi B+ or 2
  • USB Keyboard
  • USB Mouse
  • HDMI Cord

Optional Item: Ethernet Cord or Wifi dongle

Step1:

Choose an operating system to install onto the Pi. Note: If you have a Raspberry Pi 2 please use OpenElec instead of Raspbmc. (You can follow the same steps but download the OpenELEC image instead of Raspbmc)

Raspbmc

 

Raspbmc

Raspbmc runs a full version of linux underneath XBMC but because of this it is slightly slower to boot up and the interface is somewhat slower when compared to a lighter weight version such as Xbian and OpenElec.

I found this the easiest to install and doesn’t require much work to have it working perfectly. You will need to tweak it a little to get the best out of it though. This is the most popular out of the three versions.

Find out more over at the Raspbmc website. Note: Raspbmc has now been discontinued please use OpenELEC instead.

OpenELEC

OpenELEC is a very light weight simple media center for the Raspberry Pi. The pro and con for this one is that the Linux OS underneath is virtually nonexistent. This allows for much faster boot times and just faster performance overall.

The biggest drawback on this is there is little to no room to move in terms of adding new drivers etc. If you do need to this then it will require an entire rebuild of your Pi.

This is great if you have technical skills and don’t require anything else but the standard drivers for XBMC (Kodi)

Xbian

xbian

Xbian much like OpenELEC is very light weight and fast but is much easier to install and configure than OpenELEC. This has everything Raspbmc has and is virtually identical. Xbian tends to get a lot of updates which means you get some minor features before the other two variations of XBMC.

This is perfect for anyone who wants faster updates but apart from that it is basically the same as Raspbmc.

Step 2

Installing Kodi (XBMC) Onto the SD Card

There are two ways to install Raspbian unto the SD Card the first two methods require a network connection to the Raspberry Pi. If you don’t have this luxury then simply follow my guide using the offline image.

Install via NOOBS (Network Connection Required)

Follow my earlier post How to install NOBS for Raspberry Pi for this.

 Install via OpenELEC Image

  1. Download the OpenELEC Project SD Card Image from the Raspberry Pi website.
  2. You will need a formatting tool. Download SD Formatter 4.0 for either Windows or Mac.
  3. Follow the instructions to install the formatting software.
  4. Insert your SD card into the computer or laptop’s SD card reader and check the drive letter allocated to it, e.g. G:/
  5. In SD Formatter, select the drive letter for your SD card (eg. G:/) and format

Install the OpenElec Image onto the SD Card

  1. Download and install the Win32DiskImager.
  2. Unzip the OpenElec image file so it will be .img and not img.gz (7zip is useful for this)
  3. Launch the Win32DiskImager and select the OpenElec ISO file and also the drive letter your SD card is assigned (Eg. G:/)
  4. Confirm you have the correct details and click on Write.

win32diskimager1

The Boot up

  1. Plug in all your necessary equipment into the Pi. (Keyboard, mouse,power supply and WiFi adapter(optional))
  2. Turn the Pi on by plugging in the micro USB cord from the power supply. It will now boot and spend about 5-10 minutes getting everything set up.
  3. Now it is all done and ready to go but if you would like to setup network and access files then go onto the next the section.