Using Raspberry pi a lot of thinks can be done. Now in this post i will be showing you how turn your raspberry pi in to a web server.
For this we will be using a python web framework called Flask. In order to setup VNC and control Raspberry Pi from your PC use this tutorial http://www.learn2crack.com/2013/08/setup-vnc-server-in-raspberry-pi-linux.html and to set up SD card for your Raspberry Pi use this tutorial http://www.learn2crack.com/2013/08/setup-sd-card-for-raspberry-pi.html.

Steps:

1.To install flask you need to install pip. You can install it using the following command in your raspberry pi terminal.

sudo apt-get install python-pip

2.To install flask use the following command.

sudo pip install flask

3.Now you need to create a file named server_pi.py and paste the following code into it and run using the command python server_pi.py in terminal.

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
  return "Hello World!"
if __name__ == "__main__":
  app.run(host='0.0.0.0', port=80, debug=True)

Note:please make sure that the code is properly aligned.

4.Now to test the server you need to type your raspberrypi ip address(mine is 10.42.0.41) in your browser address bar.

5.If you get the message HELLO WORLD! displayed it means that your web server is working.

Enjoy 🙂

 

[Also Read: Setup Apache Web Server with PHP, MySQL in Raspberry Pi]

Any questions comment here.

Srinivasan

Srinivasan

Content Creator at learn2crack
Am an active blogger who loves programming, gaming, computer and internet tricks.
Tags:
  • Pingback: Creating Raspberry Pi Web Server Using Python |...()

  • Pingback: Creación de un servidor WEB en la Raspberry Pi con Python - Raspberry Pi | Python()

  • kennedynyaga

    Where does one create the file named server_pi.py

  • Srini Vasan

    in the raspberry pi terminal use this command nano server_pi.py to create the text file.then copy the code in to it.

    • kennedynyaga

      That creates the file in root. isn’t there www/

      • Yes it creates in root. No need for www

        • kennedynyaga

          Thanks

  • Spencer

    What do you full in for the name and main? I keep getting errors

  • Kasper Masschaele

    Will you be able to reach this web server from outside your personal network? If not, any ideas how to solve this?

    • Srini Vasan

      Sorry you can’t