The Raspberry pi is a mini computer which is designed in a single board with all the essential components required for running an operating system. The Raspberry pi is a device which uses the Broadcom controller chip which is a SoC (System on Chip). This SoC has the powerful ARM11 processor which runs on 700 MHz at its core. This minicomputer comes without a display unit, but it can be used with HDTV display or normal NTSC or PAL standard TV screen. It has an Ethernet port which allows it to be connected to a network. Operating systems from Mac, Windows and Linux can be loaded in the Raspberry pi. The capability of this inexpensive board to load operating systems from Linux and accessibility of the board through a LAN network makes it a perfect choice for tiny dedicated web servers.
This article focus on how to configure the Raspberry pi board as a web server and the technique to make it serve a graphical game for those who type the IP or address of the Raspberry pi board from the address tab of their web browser. The Raspberry pi web server is available in the same LAN network or it can be made available to anyone who has the internet connectivity using the technique of port forwarding.
In this particular project Ubuntu is installed on Raspberry pi board and is loaded on the Raspberry pi board and is connected to a router using a cross-over LAN cable. Hence the only additional hardware required with the Raspberry pi for this project is a LAN cable only.
Once connected to the router with Ubuntu OS on it, it can be accessed remotely from other systems connected in same LAN network. The board can be accessed from a Linux PC using the secure shell which is enabled in the Ubuntu of Raspberry pi board. If the IP of the Raspberry pi board in the network is say, 192.168.1.5 then the following command can be used to login as the user named ‘pi’ in the Raspberry pi;
The password for the username ‘pi’ will be prompted and it is ‘raspberry’ by default. The same can be done from the windows system with the help of software like ‘PuTTY’ which can be downloaded for free. One might find difficulty in finding the IP address of the Raspberry pi board in the LAN and it can be easily done with the help of software like ‘Ip Scanner’.
Check the IP range of the router before further editing and it can be simply found by checking the IP of the system which is use to access the Raspberry pi board. For a Linux PC the IP address can be found by using the command;
and for a windows system the IP address can be found using the command:
Now add the following lines below that commented statement;
Make sure that the will set for the Raspberry pi board is not already in use for any other PCs and it can be done by using the ‘ping’ command from both Linux and Windows PC.
If there is no PC having the IP address 192.168.1.68 then the following ‘ping’ command should fail.
Once logged into the Raspberry pi, the first think to do is to set a static IP address and it can be done by editing a single file in the Ubuntu. The file named ‘interfaces’ need to be edited and saved which is in the directory /etc/network. Open the file using the VIM editor and disable off the following statement;
iface eth0 inet static
The statement can be disabled by commenting it off like as shown below;
# iface eth0 inet static
If the IP of the PC found to be like 192.168.1.5, then write the following statements only
Save the file and it is suggested to restart the Raspberry pi board which will set the new IP address as 192.168.1.68.
If the IP of the PC found to be like 192.168.0.5, then write the following statements only
Save the file and it is suggested to restart the Raspberry pi board which will set the new IP address as 192.168.0.68.
Use the following command to reboot the Raspberry pi board;
Once the Raspberry pi reboots try to login using the new IP address.
The next step is to download and install the Apache server for the Ubuntu. It can be done using the following commands;
sudo apt-get update
sudo apt-get install apache2
Now simply copy the game folder in the directory “/var/www”. Change the permission of files in the game folder named say ‘game’, using the following command so that it can be accessed by others in the network.
chmod 777 game/*
Now open a browser in the PC and type the address of the Raspberry pi board in the address tab and start playing the game.
The Raspberry pi is connected to the port number 80 of the router and it can be forwarded to the internet by logging into the router and do the settings under ‘PORT FORWARDING’, the steps will vary from one router model to another.
Enable the forwarding of the port 80 using the following details;
Port to be forwarded : 80
Starting port number : 80
End port number : 81
Protocol : ALL or TCP/UDP
Find the public IP of the router also and if the public IP is say 188.8.131.52; then one can use the same IP to play the game from the Raspberry pi game server from anywhere around the world using a web enabled device.