View Single Post
Old March 4th, 2006   #3
oscar
A Carafe of Ubuntu
 
Join Date: Feb 2006
Beans: 126
Ubuntu 6.06
Re: Python and Apache2 (mod_python)

[EDIT] WelterPelter, I just saw that you said you used libapache-mod-python2.4 which means you are using apache not apache2. I wrote this for apache2, I dont know how different they are but i guess it wont work, i suggest installing apache2 and libapache2-mod-python[/EDIT]

To enable mod_python:
Code:
cd /etc/apache2/mods-enabled/
sudo ln -s ../mods-available/mod_python.load mod_python.load
To enable the parsing of .py scripts:
Code:
cd /etc/apache2/sites-available/
sudo gedit default
On line 10 you should have:
Code:
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride AuthConfig
                Order allow,deny
                allow from all
                # Uncomment this directive is you want to see apache2's
                # default start page (in /apache2-default) when you go to /
                #RedirectMatch ^/$ /apache2-default/
        </Directory>
Change it to:
Code:
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride AuthConfig
                Order allow,deny
                allow from all

                AddHandler mod_python .py
                PythonHandler mod_python.publisher
                PythonDebug On

                # Uncomment this directive is you want to see apache2's
                # default start page (in /apache2-default) when you go to /
                #RedirectMatch ^/$ /apache2-default/
        </Directory>
Save the file.
Now restart your server:
Code:
sudo /etc/init.d/apache2 restart
Test it:
Code:
sudo gedit /var/www/test.py
insert these lines:
Code:
def index(req):
  return "Test successful";
and it should work
visit http://localhost/test.py and it should say "Test successful" in plain text

Last edited by oscar; March 6th, 2006 at 05:19 PM..
oscar is offline   Reply With Quote