Visit my website New

Sunday, 20 December 2015

Raspberry Pi Apache Server Led ON OFF

Install Apache

Apache is a Popular web server, it can serve HTML files over HTTP, and with additional modules can serve dynamic webpages using scripting language such as PHP. It can be installed on Raspberry Pi.

First install apache2 package

sudo apt-get install apache2 -y

Test the web server 

By default, Apache puts a test HTML file in the web folder. The default webpage is served when you browse to http://localhost/ on the pi itself or (Your Pi's ip address).

raspberry pi default apache page

This means you have Apache working!

The default webpage is just html file on the system. 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/ 

ls -al

This shows the content of the file along with user which owns the file, file size and last modification date & time.

Additional -Install PHP

PHP helps to execute the python file dynamically on the webpage. To install PHP on Raspberry Pi,
sudo apt-get install php5 libapache5-mod-php5

Creating a PHP file to execute the python file on the webpage:

Move to the directory /var/www 

Create a file named index.php and place the following codes.

Download the index.php file
The webpage could look like below

The python file for each button should be like this
LED ON (      LED OFF (

Monday, 30 November 2015

Access Raspberry Pi Wireless using Laptop (Pi as Access Point)

If you would like to make your raspberry pi as access point or wifi router, the following tutorial would help.

You will need a Wi-Fi adapter for raspberry pi. The following adapter i prefer,

A USB WiFi (

Edimax wifi adapter for raspberry pi

Getting it done!

Plug the adapter of on the Raspberry pi's USB port. On the terminal enter,

dmesg | more

You will see some thing similar to the following lines at the end..

[3.282651] usb 1-1.2: new high-speed USB device number 4 using  dwc_otg

[3.392819] usb 1-1.2: New USB device found, idVendor=392, idProduct=7811

[3.407489] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3

[3.420530] usb 1-1.2: Product: 802.11n WLAN Adapter

If you get this, then your OS has recognised the Wi-Fi adapter.

Install the necessary Software

      In order to make the Raspberry Pi to act as a WiFi router and access point we need to install some extra softwares.


HostAPD is a user space daemon for access point and authentication servers. That is it will turn the raspberry pi as access point so that the other computers can connect to it. It will also handle security such that we can setup a Wifi password for it.


isc-dhcp-server is the internet system consortium's implementation of a DHCP server. A DHCP server is responsible for assigning address to computers and devices connection to the Wi-Fi acess point.

Run the following command to install DHCP.

sudo apt-get install isc-dhcp-server

Next up is the HostAPD software. Because our USB stick needs an access point driver, we need to install a custom version compiled with the driver we need.


tar -zxvf v1.1.tar.gz

cd RTL8188-hostapd-1.1/hostapd

sudo make

sudo make install

Configure the ISC-DHCP-Server

To configure the DHCP server open the file /etc/dhcp/dhcp.conf in your favorite text editor.

sduo nano /etc/dhcp/dhcp.conf

Find the following section and comment it out by placing a hashtag at the beginning of the line.

option domain-name "";

option domain-name-servers,;

Next find the section below and un-comment authoritative.

#If this DHCP server is the official DHCP server for the local

#network, the authoritative directive should be uncommented.


The file should look as like below:

Next we need to define the network and network address that the DHCP server will be serving. This done as shown below at the end of the file.

This will enable the DHCP server to hand out the ip address from to in its own local network. This configuration will use the Google DNS servers at and

To save the file press Ctrl+O this will write the file to the disk - afterwards you can exit nano by Ctrl+X.

Next file to edit is /etc/default/isc-dhcp-server

sudo nano /etc/default/isc-dhcp-server

Scroll down to the line saying interfaces and update the line to say:


The last step in configuring DHCP server is to configure ip address for the wireless network adapter. This is done in the file /etc/network/interfaces before opening it make sure the WLAN is down.

sudo ifdown wlan0

sudo nano /etc/network/interfaces

Change the file to look like this:

This will make the wireless adapter take the address 192.16810.1.

Configuring HostAPD

To configure HostAPD, open the file called /etc/hostapd/hostapd.conf

sudo nano /etc/hostapd/hostapd.conf

The standard configuration will create a new wireless network called wifi with the password YourPassPhrase . You can edit the parameter "ssid=wifi" to the SSID name you want and "wpa_passphrase=YourPassPhrase" to your own password.

Enable NAT

The last step before we can start the access point is setting up Network address Transmission(NAT).
Open /etc/sysctl.conf with 

sudo nano /ect/sysctl.conf

Scroll down to the last line of the file and add the line:


Next start the translation right away by running:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Start the wireless network by running;

Next step up the actual translation between the ethernet port called eth0 and the wireless card called wlan0.

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED, ESTABLISHED -j ACCEPT

sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Thus NAT configured

Starting your wireless router

sudo service -sc-dhcp-server start
sudo service hostapd start

At this point you should be able to find your wireless network access on your laptop.


The point it is not so cool you have to login every time it reboots to start the HostAPD and DHCP software...

To avoid this run the following commands:-

sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable

To avoid to configure NAT every time the Raspberry Pi reboots you can do the following.
Run this command to backup the NAT configuration.

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Add the following to the end of the file /etc/network/interfaces to restore the configuration
when the network interfaces comes up

up iptables-restore < /etc/iptables.ipv4.nat

The file should look like:

sudo nano /etc/network/interfaces

Finally reboot the system

sudo reboot

Saturday, 10 October 2015

Install VNC for Raspberry PI

                Refer my previous posts, though you use Xming. I personally recommend to use VNC. VNC(Virtual Network Computing) is a graphical desktop sharing system that allows you to remotely control the desktop interface of one computer from another. It transmits the Keyboard and the mouse events from the controller, and receives updates to the screen over the network from the remote host.

Step 1:

- On your raspberry pi, install TightVNC package:

$ sudo apt-get install tightvncserver

vnc server raspberry pi

$ tightvncserver

- next, run TightVNC Server which will prompt you to enter a password and an optional view-only password.

-start VNC server from the terminal. e.g.:

$ vncserver :1


- On your computer install VNC client.
VNC on mac looks like this. The entire desktop of pi is seen on Mac.

vnc on mac

Friday, 12 June 2015

Raspberry Pi without External Monitor

Step 2: Assign ip address

                 Before you insert your memory card into your Pi if you are trying to Pi without external monitor do these steps.
  1. Open the SD card drive.
  2. Open file named cmdline.txt in notepad or any word editor.
  3. Type ip address that you want to assign to your raspberry pi.(you can delete this after some process).
assign IP address just exactly after rootwait

Step 3: Connect your pi to your computer via Ethernet.

             After finishing step2 take out the memory card from the computer, insert it into the Raspberry Pi. Use Ethernet cable your computer and Pi. Power ON your pi. We will not see the booting process since we are using it without monitor.
                   To access Raspberry pi without monitor we need Putty installed on the computer and we also need Xming. Open up Putty, after you doing the above process.
       Type your Pi's IP address and under category tab click on SSH, under X11 tick enable Xming.
Xming is an display server for windows. Click open in the Putty.
We will get the display as shown below.

Type: login as:pi

*while typing password it will not be displayed, just type and give enter.
Type "sudo-raspi-config"
Expand the file system and click finish.
Pi reboots,
Now again start step3 but with xming running.
after logging in into the pi type: startxlde-pi

Now you are accessing the Pi without monitor.

**note: we need configure /etc/network/interfaces so that we can remove the rootwait ip which we have previously typed.
see this in my next post.

Saturday, 23 May 2015

Configure Raspberry Pi2

       Raspberry Pi is a Credit Card sized Computer....I am skipping all introductions.

You have bought raspberry pi 2, A Micro SD card size at least 8GB. Can you work on Raspeberry Pi without monitor? Yes you can do.

Raspberry Pi
Raspberry Pi sd card
SanDisk SD Card for Raspberry Pi

Step1: Mount the OS on the SD Card.

        Pi needs an operating system to work on. You can download OS for Raspberry Pi from download. There are Raspbian OS and other third party OS available. I have downloaded the Raspbian OS by Debian Wheezy.

You need to mount the Operating System on the SD card.
Insert the SD card into your system via any SD card reader. To write the image on the SD card, if you use Windows operating system you need to install the Win32Disk image utility on your windows system  Source Forge project page. Open the Utility software and select the image (OS Raspbian), Select the Drive of the SD Card and Click write.. 
It take some time Until the Process Gets over.
Done. If you don't have a monitor to connect to Pi you can use your laptop itself as monitor. Check my next Post.

Mount SD Card