July 14, 2013

Raspberry Pi + Python + Tornado + NGinx + MongoDB

Do you need a simple web server at home? If you have a low budget, you don't need a supercomputer and you don't want to buy a cloud virtual server account, this is the solution that's right for you.

A super combo webserver combination of instruments:

1. Prepare your Rapberry Pi (with SD card 16GB class10 or greater)


Download the raspberry pi OS following this guide here:

IMPORTANT: prevent the Raspberry pi SHOCK overheating by installing a heat sink cooler and a 5v fan. 

Install the raspbian os (easier and faster than the others). Connect keyboard, ethernet (or wifi), mouse and monitor. Expand the partition and set the current location for the timezone from the raspconfig menu, and startx (if you want to go in windows style). 
Open terminal window and make a:
  • sudo apt-get update 
  • sudo apt-get upgrade
Install SSH package to take control from remote (if not present): 
  • sudo apt-get install ssh
You should now access to the raspberry from your pc via ssh. For windows bash link command-console you can use putty.exe 
Create a user with the adduser command or use pi default user: pi@raspberry



2. Check Python in your rasp


type   python in your shell.  If you get:

Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>>


it's ok, and go to the step 3.  Otherwise install python 2.7 with sudo apt-get install python. Check python after installation and go to the step 3.





3. Install Tornado Web Server




Here the setup part:

First things first, install Tornado on your Raspberry Pi:1.  Good thing to do before every install – update agt-get and installed packages
sudo apt-get update
sudo apt-get upgrade
2.  Install easy_install and pip (which are Python package managers)
sudo apt-get install python-pip python2.7-dev
3.  Update your easy_install (and pip) package definitions
sudo easy_install -U distribute
4.  Now install Tornado using pip
sudo pip install tornado

To make sure everything works, create a file named “server.py” containing the following code (taken from Tornado’s site), and run it from terminal using the command “python server.py”










import tornado.ioloop
import tornado.web
 
class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")
 
application = tornado.web.Application([
    (r"/", MainHandler),
])
 
if __name__ == "__main__":
    application.listen(8080)
    tornado.ioloop.IOLoop.instance().start()
Now on a separate computer on the same network, navigate your browser to http://raspberrypi:8080 (or use the IP address for example 192.168.1.7:8080).  You should see “Hello, world” if everything goes right.




4. Install NGinx (optional - increase performances)


Open a terminal and execute:
sudo apt-get install nginx
setup nginx... (coming soon..).




Raspberry: How to Backup Raspberry PI SD card

 Step 1: Startup the "Win32DiskImager" program, 
http://sourceforge.net/projects/win32diskimager/



Here's the opening screen: Notice you will need to select which drive is your SDcard. in this case my SDcard is E:\ then click the NAVIGATE icon just next to the E:\ pulldown box, this will open a file-explorer window. (Also note that the "read" button is not available to use just yet).

Step 1a:  insert the SD card destination and write the copied image. If you have an error about the destination blocks number (or sd size even it is the same size) go to the STEP 2.

Step 2: Use DD (windows version here: http://www.chrysocome.net/dd)



Use DD to resize img win32diskimager partition just like the screenshot above.

Step 3: Use Win32DiskImager to copy the DD image in the new sd card.


Realtek Network Controller was not found. ERROR


First try to update your lan driver.
If you get this message when installing lan driver:

"The Realtek Network Controller was not found.
If Deep Sleep Mode is enabled Please Plug the Cable."


you probably need to update your BIOS.

I solved this problem on my HP DV6 2135sl notebook with Windows 7 x64.
Drivers:
http://h10025.www1.hp.com/ewfrf/wc/softwareList?os=4063&lc=it&dlc=it&cc=it&lang=it&product=4106866#