Jason Bennett's Developer Corner

 






Click to see the XML version of this web page.

>


View David Jason Bennett's profile on LinkedIn

 

 

A Little About Jason Bennett ...

I've had an interest in publishing technical articles and HELPFUL code for a few years.  I am (by trade and hobby) a developer who specializes in Oracle technologies and web based architectures.  I have been an employee of both TUSC and Oracle Corporation.  My intent here is to share my ideas and coding experiences with the developer community as a whole.  As with all developers some of my ideas are great and some of them are ....  well you know.  Anyway, I hope you find something here that will aid in your endeavor, or spark a new idea. 

I am more than happy to assist with technical issues and will even write a little code if need be. If you find something on the site that is really useful and you'd like to make a contribution (absolutely up to you and absolutely not required), just click the "Make a Donation" button on the left!

Good luck and good coding !




  Monday, October 25, 2004


Installing Mod_python 2.7.10 on OracleAS 10g under Linux

 

   Python is a powerful and free  object-oriented programming language much like Perl, PHP, and Java.  Python is open source software and is maintained by the open source developer community (http://www.python.org).    Mod_python is an Apache module that allows the Python interpreter to run imbedded within the Apache server.  This article details how to build (compile) Mod_python 2.7.10 and install it under OracleAS 10g.

 

Prerequisites

(Note: The latest version of Mod_python is 3.1.3, but it only runs under Apache 2.0. OracleAS 10g is built on Apache version 1.3)   There are a few prerequisites for getting Mod_python 2.7.10 to run under OracleAS 10g. 

 

  • A Python interpreter must be installed on your Linux system in non-threading mode. Please refer to installation instructions provided with the Python distribution for more detail.

 

    • The latest release, Python 2.3.4, is not supported under Mod_python 2.7.10.  I recommend Python release 2.1.3.  It can be downloaded from http://www.python.org.  If you have a pre-existing version of Python, it was most likely compiled with threading enabled.  I recommend creating a second install, and placing the path to the second python  executable ahead of the existing python executable in the system path ($PATH). You may have to reboot the box make sure the path change takes affect if you made the change in /etc/profile file.
    • Python must be compiled in non-threading mode since Apache does not support threading.  Here is an example of how the configure command would look:
      • ./configure -–with-threads=no
  • Make sure that libdms2.so is included in your LD_LIBRARY_PATH.  I recommend placing it in /usr/lib.  libdms2.so is a shared object library that contains DSO related functions.  Oracle provides libdms2.so on the RepCA installation CD under the /utilities/plug-ins/oc4j directory.
  • Download Mod_python 2.7.10 binaries from http://httpd.apache.org/modules/python-download.cgi and explode the tarfile in your directory of choice.  I prefer to place mine in /opt. So, the path to my sources is /opt/mod_python-2.7.10

 

Building and Installing Mod_python

   Building and installing Mod_python is simply a matter of following the next few steps (do this as root):

 

  1. Before running the build scripts, I recommend copying all of the .h files from <parent> /Python-2.1.3/Include and $ORACLE_HOME/Apache/Apache/include to <parent>/mod_python-2.7.10/src/include. This will ensure that all of the required header files are present.
    1. Note:  Later, the compiler may complain about conflicts of the gethostname function in the ap_config.h header file with another .h file.  If this happens, edit the ap_config.h file that you copied into <parent>/mod_python-2.7.10/src/include and comment out the first and second occurrences of int gethostname.
    2. Note: The compiler may complain about functions in /usr/include/string.h. If this happens, then copy /usr/include/string.h to <parent>/mod_python-2.7.10/src/include. Edit the file and change the following line, # ifdef __USE_BSD to # ifdef __USE_LINUX
  2. The next step is to run the configure script which sets up the properties in the Makefile for linking and compiling mod_python.so .  Since we are utilizing DSO (Dynamic Shared Object) support with Apache, we need to specify the -–with-apxs=<path to Apache apxs script> flag with the configure script.  We will also need to include the path the Python interpreter sources using the -–with-python=<path to Python sources> flag.  That being said, execute the following command with paths specific to your environment:
    1. ./configure --with-python=/opt/Python-2.1.3 --with-apxs=/opt/oracle/product/OracleAS10g_app/Apache/Apache/bin/apxs
  3. The next step is to run the make command.  Before doing so, navigate to the <parent>/mod_python-2.7.10/src directory and edit the entries INCLUDES and LIBS in the file Makefile to match the following (substituting paths specific to your environment):
    1. INCLUDES=-I/opt/mod_python-2.7.10/src/include -I/include -I/opt/Python-2.1.3 -I/opt/Python-2.1.3/Include -DEAPI
    2. LIBS=-lm  /opt/Python-2.1.3/libpython2.1.a -ldl -lutil -lm /usr/lib/libc.a -ldl –lutil
  4. Navigate back to <parent>/mod_python-2.7.10 and execute the following command:
    1. make
  5. If no errors were reported, then execute the following command:
    1. make install

 

At this point, the shared object library, mod_python.so should have been created and automatically copied to $ORACLE_HOME/Apache/Apache/libexec.  Next, we need to configure Apache to load mod_python.so.

 

Configuring and Testing OracleAS 10g Apache

 

Since we compiled mod_python as a DSO, we need to instruct Apache to load the module at startup by adding the following line to the httpd.conf file.

 

LoadModule python_module libexec/mod_python.so

 

Now, we want to make sure that we can actually execute a Python file:

 

  1. Make a directory, such as htdocs/python, in which to store your .py or Python script.
  2. Add the following Apache directives to your httpd.conf file:

 

               Alias  /py/  /some/directory/htdocs/python”

 

               <Directory /some/directory/htdocs/python>

                   AddHandler python-program .py

                  PythonHandler mptest

                  PythonDebug On

              </Directory>

  1. Create a file called mptest.py in the /some/directory/htdocs/python directory with the following content:

                    from mod_python import apache

 

                  def handler(req):

                  req.send_http_header()

                 req.write("Mod_Python on OracleAS 10g!!")

                 return apache.OK

 

      4.  After restarting OHS,  open a web browser and point it to the URL referring to mptest.py (http://<;server>:<port>/py/mptest.py).  You should see “Mod_Python on OracleAS 10g!!”.

 

 

Wrapping it Up

After following the steps above, you should have a working version of Mod_python installed under OracleAS 10g.  For more information on what you can do with Mod_python and Python, please refer to the documentation included with each distribution (it’s pretty good), or visit http://www.python.org ot http://www.modpython.org


9:43:43 PM    

Click here to visit the Radio UserLand website. © Copyright 2008Jason Bennett.
Last update: 8/28/2008; 9:44:07 PM.

October 2004
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Aug   Nov