Python “Hello World” web application in Ubuntu 11.10

This python tutorial is for showing how to setup the web development environment under Ubuntu 11.10 and make hello world example.

So Python has become a hot word in recent years. But before you can do anything about it, you need a "hello world" sample application. In this tutorial, I will build a hello world Python web application under Ubuntu 11.10. All software versions are under Ubuntu 11.10's default setting.

1. Install Apache server. This is the HTTP server that will handle the request.

Try the following command and and open a browser and type "localhost", if server is up go to step 2.

sudo /etc/init.d/apache2 start

If server is not running, use the following command to install:

sudo apt-get install apache2

2. Install mod_python. This is the module that is used to process .py files.

sudo apt-get install libapache2-mod-python

3. Configure Apache server. (If you configure PHP on Apache server, this is almost the same)

Even now you have installed mod_python in step 2, Apache server does not know how to handle .py files. We need to add a handler to part and make it like the following:

sudo vi /etc/apache2/sites-available/default

(you need to be in sudo mode to be able to edit "default" file!)

4. Write your "hello world" program.

sudo vi /var/www/

def index(req):
  return "Hello World";

It looks like the following, and be careful about indentation.

5. Restart Apache server and run your first Python web application.

sudo /etc/init.d/apache2 restart

You should be able to get your "hello world" web app correctly running.

You can now start exploring Python world, either by reading a book or google search!

Category >> Python  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";

  1. Ankur on 2015-7-8

    Hey.. I follow the procedure on 12.04…. But after following the procedure.. when I write localhost/ in browser… it says to me open the file or download it

  2. Kamil on 2016-12-30

    Probably you created a file named in step :
    sudo vi /var/www/

    And in web browser you tried to use
    Try to use or rename in to 🙂

Leave a comment