this is obsolete doc -- see http://doc.nethence.com/ instead

Apache/mod_python configuration 

 

 

Installation 

Fetch and install mod_python (http://archive.apache.org/dist/httpd/modpython/), 

wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz
cd mod_python-3.3.1/
./configure && make && make install

 

Configure Apache to load the module, 

cd /etc/httpd/conf.d/
echo 'LoadModule python_module modules/mod_python.so' >> modules.conf

 

 

Configuration 

Configure your virtual host to use the publisher handler, 

cd /etc/httpd/conf.d/
vi your_vhost.conf

 

For the Publisher handler, add this to your virtual host configuration, 

        <Directory /path/to>
          AddHandler mod_python .py
          PythonHandler mod_python.publisher
          PythonDebug On
        </Directory>

 

Or for the PSP (Python Server Pages) handler, 

        <Directory /path/to>
           AddHandler mod_python .psp .psp_
           PythonHandler mod_python.psp
           PythonDebug On
        </Directory>

 

Note. directory path is important. The python script can be in that directory or in subdirectories. 

 

 

Ready to go 

Apply. On Redhat system, 

service httpd restart

or on Slackware, 

/etc/rc.d/rc.httpd restart

 

You can now try the "form" example (http://www.modpython.org/live/current/doc-html/tut-pub.html#tut-pub) with the Publisher handler, or the PSP examples (http://webpython.codepoint.net/mod_python_psp) with the PSP handler. 

 

refs (psp). 

http://webpython.codepoint.net/mod_python_psp (nice favicon! http://webpython.codepoint.net/favicon.ico) 

http://www.modpython.org/live/current/doc-html/hand-psp.html 

http://www.modpython.org/live/current/doc-html/pyapi-psp.html 

http://onlamp.com/pub/a/python/2004/02/26/python_server_pages.html 

 

 

Troubbleshooting 

If the publisher handler doesn't work try with mptest (http://www.modpython.org/live/current/doc-html/inst-testing.html). 

 

If you got this error trying to access mptest.py, 

ImportError: No module named mptest

==> check the Directory directive and the path it applies to 

 

 

Python / Oracle 

Do you need to connect to an Oracle database? 

 

First, make sure an Oracle client is installed, 

updatedb
locate libclntsh

See http://pbraun.nethence.com/oracle/10g_client.html for more details. 

 

Now let's install the cx_Oracle Python module (http://cx-oracle.sourceforge.net/), 

cd ~/
wget http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.1-10g-py24-1.x86_64.rpm?download
rpm -ivh cx_Oracle-5.1-10g-py24-1.x86_64.rpm
ls -l /usr/lib/python2.4/site-packages/cx_Oracle.so

ref. http://www.orafaq.com/wiki/Python 

 

Make sure LD_LIBRARY_PATH points to /home/oracle/client10g/lib and proceed, 

echo $LD_LIBRARY_PATH
python

e.g., 

import cx_Oracle
connection = cx_Oracle.connect('USERNAME/PASSWORD@dbname')
cursor = connection.cursor()
cursor.execute('select table_name from user_tables')
print cursor.description
#print cursor.fetchone()
print cursor.fetchall()
cursor.close()
connection.close()

 

Refs. 

http://wiki.oracle.com/page/Python 

http://www.orafaq.com/wiki/Python