Python and Apache2 (mod_python)
We first must have package libapache2-mod-python installed for apache2.
To enable mod_python:
Code:
cd /etc/apache2/mods-enabled/
sudo ln -s ../mods-available/mod_python.load mod_python.load
Code:
cd /etc/apache2/sites-available/
sudo gedit default
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>
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>
Now restart your server:
Code:
sudo /etc/init.d/apache2 restart
Code:
sudo gedit /var/www/test.py
Code:
def index(req):
return "Test successful";
visit http://localhost/test.py and it should say "Test successful" in plain text
Last edited by oscar; March 6th, 2006 at 04:19 PM ..