Global Constant
Steve Nay's ramblings

Using Python and Apache 2 on Ubuntu

This is the first in a series of posts detailing my experiences and discoveries as a TA for Phil Windley’s CS 462 class, “Large-scale Distributed System Design.” Most of the posts will be how-tos, with perhaps the occasional architectural discussion or piece of insight. Enjoy the ride!

We’re using Amazon EC2 in this class. The first thing I managed to do was get an Ubuntu server up and running (using 10.04 LTS). This wasn’t too hard. The next part was getting Apache 2 and Python installed so I can get a basic web server going. This required the following packages:

  • apache2 (and all it's dependencies)
  • libapache2-mod-python
  • ... and a few other python-* libraries that I won't detail here.

All fine and dandy. It amazed me how fast apt-get install was able to run, since there appears to be an Ubuntu repository hosted on S3 in the same region.

But Apache won’t actually run Python files until you configure it to do so. I did this by editing /etc/apache2/sites-available/default and adding three lines to right section. I put them in the <Directory /var/www/> section, since that’s where my code is going to go.

    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

        DirectoryIndex index.html

        AddHandler mod_python .py
        PythonHandler mod_python.publisher
        PythonDebug On

And it works! Awesome.