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):
- 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.
- 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.
- 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
- 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:
- ./configure --with-python=/opt/Python-2.1.3 --with-apxs=/opt/oracle/product/OracleAS10g_app/Apache/Apache/bin/apxs
- 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):
- 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
- LIBS=-lm /opt/Python-2.1.3/libpython2.1.a -ldl -lutil -lm /usr/lib/libc.a -ldl –lutil
- Navigate back to <parent>/mod_python-2.7.10 and execute the following command:
- make
- If no errors were reported, then execute the following command:
- 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:
- Make a directory, such as htdocs/python, in which to store your .py or Python script.
- 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>
- 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
|
|